User Tools

Site Tools


harlowe:macro_syntax

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

harlowe:macro_syntax [2017/06/20 02:02]
l
harlowe:macro_syntax [2017/10/09 20:39]
Line 1: Line 1:
-====Macro syntax==== 
-In Harlowe, macros are called by writing the name, a colon, and some data values to provide it, all in parentheses. For instance, you call the [[harlowe:​print|(print:​)]] 
-macro like so: ''​%%(print:​ 54)%%''​. In this example, ''​%%print%%''​ is the macro'​s name, and ''​%%54%%''​ is the value. 
  
-The name of the macro is case-insensitive,​ dash-insensitive and underscore-insensitive. This means that 
-any combination of case, dashes and underscores in the name will be ignored. You can, for instance, write 
-''​%%(go-to:​)%%''​ as ''​%%(goto:​)%%'',​ ''​%%(Goto:​)%%'',​ ''​%%(GOTO:​)%%'',​ ''​%%(GoTo:​)%%'',​ ''​%%(Go_To:​)%%'',​ ''​%%(Got--o:​)%%'',​ ''​%%(-_-_g-o-t-o:​)%%'',​ or 
-any other combination or variation. 
- 
-You can provide any type of data values to a macro call - numbers, strings, booleans, and so forth. These 
-can be in any form, as well - ''​%%"​Red"​ + "​belly"​%%''​ is an expression that produces a single string, "​Redbelly",​ 
-and can be used anywhere that the joined string can be used. Variables, too, can be used with macros, if 
-their contents matches what the macro expects. So, if ''​%%$var%%''​ contains the string "​Redbelly",​ then ''​%%(print:​ $var)%%'',​ 
-''​%%(print:​ "​Redbelly"​)%%''​ and ''​%%(print:​ "​Red"​ + "​belly"​)%%''​ are exactly the same. 
- 
-Furthermore,​ each macro call produces a value itself - [[harlowe:​num|(num:​)]],​ for instance, produces a number, [[harlowe:​a|(a:​)]] an array - so 
-they too can be nested inside other macro calls. ''​%%(if:​ (num:"​5"​) > 2)%%''​ nests the [[harlowe:​num|(num:​)]] macro inside the [[harlowe:​if|(if:​)]] macro. 
- 
-If a macro can or should be given multiple values, separate them with commas. You can give the ''​%%(a:​)%%''​ macro 
-three numbers like so: ''​%%(a:​ 2, 3, 4)%%''​. The final value may have a comma after it, or it may not - ''​%%(a:​ 2, 3, 4,​)%%''​ 
-is equally valid. Also, if you have a data value that's an array, string or dataset, you can "​spread out" all 
-of its values into the macro call by using the ''​%%...%%''​ operator: ''​%%(either:​ ...$array)%%''​ will act as if every value in 
-$array was placed in the [[harlowe:​either|(either:​)]] macro call separately. 
harlowe/macro_syntax.txt ยท Last modified: 2017/10/09 20:39 (external edit)