set: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
Line 1: Line 1:
{{MacroFunction
{{MacroFunction
|name=set
|name=set
|description
|description=
Sets the value of a variable.
Sets the value of a variable.
 
<p>
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.
</p>
|usage=
|usage=
<source lang="mtmacro" line>
<source lang="mtmacro" line>
Line 10: Line 12:


|example=
|example=
A simple use:
<source lang="mtmacro" line>
<source lang="mtmacro" line>
    [h: set("test", 33)] [r:test]
[h: set("test", 33)]
[r: test]
</source>
</source>
Returns  
Returns  
     33
     33
A more sophisticated example that shows passing a string expression as the first parameter:
<source lang="mtmacro" line>
[h: var1="te"]
[h: var2="st"]
[h: set(var1+var2, 33)]
[r: test]
</source>
Returns
    33
Both of the above examples are equivalent to:
<source lang="mtmacro" line>
[r: test = 33]
</source>
}}
}}
[[Category:Miscellaneous Function]]
[[Category:Miscellaneous Function]]

Revision as of 01:04, 3 March 2019

set() Function

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)]

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]