Project

General

Profile

Var » History » Version 15

Per Amundsen, 12/29/2018 09:25 AM

1 1 Per Amundsen
_Added in 1.8.8_
2
3 12 Per Amundsen
*/var [-gnsp] <%var> [[= ]value]*
4 1 Per Amundsen
5
Sets the value of local variable %var to the specified value.
6
7 6 Per Amundsen
Syntax can be either _var %var = value_ or _var %var value_.
8 5 Per Amundsen
9 9 Per Amundsen
Multiple variables can be set in one line using comma as separator, _var %var1 = value, %var2 = value2_.
10 5 Per Amundsen
11 15 Per Amundsen
_See also [[/set]], [[/unset]]._
12 14 Per Amundsen
13 1 Per Amundsen
*Switches*
14
15
-s - Display variable assignment value.
16
-g - Creates a global variable instead.
17
-n - Treat the value as plain text, even if arithmetic operators are used.
18 13 Per Amundsen
-i - Initializes a variable only if it does not already exist as a local or global variable.
19
-p - Permits value to be 2 literal double quotes and permits value to end with a single [[$chr]](32) space. Also enables -n switch behavior.
20 1 Per Amundsen
21
*Parameters*
22
23
<%var> - The variable to set.
24 11 Per Amundsen
[[= ]value] - Value to set the variable to. (can be a single [[Arithmetic Operators|arithmetic expression]])
25 1 Per Amundsen
26
*Example*
27
28 2 Per Amundsen
<pre>
29 3 Per Amundsen
alias factorial {
30 1 Per Amundsen
  var %result = 1, %x = $1
31
  while (%x) {
32
    var %result = %result * $v1
33
    dec %x
34
  }
35
  return %result
36
}
37 3 Per Amundsen
38
;Returns 3628800
39
//echo -ag $factorial(10)
40 2 Per Amundsen
</pre>