set: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 9: | Line 9: | ||
</p> | </p> | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: set(varName, val)] | [h: set(varName, val)] | ||
</ | </syntaxhighlight> | ||
'''Parameters''' | '''Parameters''' | ||
{{param|varName|Variable name or a string containing a valid variable name.}} | {{param|varName|Variable name or a string containing a valid variable name.}} | ||
Line 18: | Line 18: | ||
|example= | |example= | ||
A simple use: | A simple use: | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: set("test", 33)] | [h: set("test", 33)] | ||
[r: test] | [r: test] | ||
</ | </syntaxhighlight> | ||
Returns | Returns | ||
33 | 33 | ||
A more sophisticated example that shows passing a string expression as the first parameter: | A more sophisticated example that shows passing a string expression as the first parameter: | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: var1="te"] | [h: var1="te"] | ||
[h: var2="st"] | [h: var2="st"] | ||
[h: set(var1+var2, 33)] | [h: set(var1+var2, 33)] | ||
[r: test] | [r: test] | ||
</ | </syntaxhighlight> | ||
Returns | Returns | ||
33 | 33 | ||
Both of the above examples are equivalent to: | Both of the above examples are equivalent to: | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[r: test = 33] | [r: test = 33] | ||
</ | </syntaxhighlight> | ||
}} | }} | ||
[[Category:Miscellaneous Function]] | [[Category:Miscellaneous Function]] |
Revision as of 21:10, 14 March 2023
set() Function
• Introduced in version 1.3b48
Sets the value of a variable.
This function is rarely used because a simple assignment to a variable name can be used instead. However, using this function allows the first parameter to be a variable that identifies the variable name to be assigned.
Usage
[h: set(varName, val)]
Parameters
varName
- Variable name or a string containing a valid variable name.val
- The value to set the variable to.
Example
A simple use:
[h: set("test", 33)]
[r: test]
Returns
33
A more sophisticated example that shows passing a string expression as the first parameter:
[h: var1="te"]
[h: var2="st"]
[h: set(var1+var2, 33)]
[r: test]
Returns
33
Both of the above examples are equivalent to:
[r: test = 33]