From WikiChip
Editing mirc/commands/var
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.
Latest revision | Your text | ||
Line 4: | Line 4: | ||
The Local Variables created by /var exist only within the :event: or ALIAS where they were created. If your event or alias calls another alias, that alias cannot see the local values unless passed to them in another way, such as a parameter used when calling the alias. | The Local Variables created by /var exist only within the :event: or ALIAS where they were created. If your event or alias calls another alias, that alias cannot see the local values unless passed to them in another way, such as a parameter used when calling the alias. | ||
− | The var command can perform one math operation via one of the arithmetic operators: addition (+), subtraction (-), multiplication (*), division (/), modulo (% | + | The var command can perform one math operation via one of the arithmetic operators: addition (+), subtraction (-), multiplication (*), division (/), modulo (%), and exponent (^). They ''must'' be space delimited with both operands being a number. If any of the operands are not a number or if a space is missing, it will be treated as plain text. |
Note: Unlike the {{mIRC|/set}} command, var can assign a value to multiple variables at once. | Note: Unlike the {{mIRC|/set}} command, var can assign a value to multiple variables at once. | ||
Line 16: | Line 16: | ||
== Synopsis == | == Synopsis == | ||
− | /var [- | + | /var [-sg] <%var> [[= ]value] |
/var [-sg] <%var> <number> <+ | - | * | / | %> <number> | /var [-sg] <%var> <number> <+ | - | * | / | %> <number> | ||
− | /var [-sg] <%var> [= ]<number> <+ | - | * | / | % | + | /var [-sg] <%var> [= ]<number> <+ | - | * | / | %> <number> |
/var [-sg] <%var> [[= ]value][, <%var> [[= ]value]][, ...] | /var [-sg] <%var> [[= ]value][, <%var> [[= ]value]][, ...] | ||
− | /var [-sg] <%var> [= ]<number> <+ | - | * | / | % | + | /var [-sg] <%var> [= ]<number> <+ | - | * | / | %> <number>[, ...] |
== Switches == | == Switches == | ||
Line 33: | Line 33: | ||
* Note: See the {{mIRC|/set}} page for more info about setting dynamic variable names using identifiers like $nick or $network | * Note: See the {{mIRC|/set}} page for more info about setting dynamic variable names using identifiers like $nick or $network | ||
* Note: much of the usage of /var is similar to that of /set except that switches like -uN or -e or -z or -k have no meaning for local variables which cease to exist when the event or alias is finished. | * Note: much of the usage of /var is similar to that of /set except that switches like -uN or -e or -z or -k have no meaning for local variables which cease to exist when the event or alias is finished. | ||
− | |||
== Parameters == | == Parameters == | ||
* '''<%var>''' - The name of the variable | * '''<%var>''' - The name of the variable | ||
* '''[value]''' - The value to assign to the variable. If not present or is $null the local var is unset | * '''[value]''' - The value to assign to the variable. If not present or is $null the local var is unset | ||
* '''<number>''' - Any arbitrary numerical value, can be a floating point number | * '''<number>''' - Any arbitrary numerical value, can be a floating point number | ||
− | * '''< + | - | * | / | % | ^ | + | * '''<+ |''' - | * | / | % | ^ > - One of the six possible arithmetic operations |
* '''<number>''' - Any arbitrary numerical value, can be a floating point number | * '''<number>''' - Any arbitrary numerical value, can be a floating point number | ||
− | |||
− | |||
== Example == | == Example == | ||
Line 81: | Line 78: | ||
//var %a 2^16 | var %b 2 ^ 16 | echo -a %a because not tokenized by spaces vs %b | //var %a 2^16 | var %b 2 ^ 16 | echo -a %a because not tokenized by spaces vs %b | ||
returns: 2^16 because not tokenized by spaces vs 65536 | returns: 2^16 because not tokenized by spaces vs 65536 | ||
− | |||
− | |||
//var %a 1 + 1 + 1 | echo -a %a because only 1 math operation allowed | //var %a 1 + 1 + 1 | echo -a %a because only 1 math operation allowed | ||
returns: 1 + 1 + 1 because only 1 math operation allowed | returns: 1 + 1 + 1 because only 1 math operation allowed | ||
Line 90: | Line 85: | ||
<syntaxhighlight lang="mIRC"> | <syntaxhighlight lang="mIRC"> | ||
− | -i causes /var to act only if local var does not exist, even if it is | + | -i causes /var to act only if local var does not exist, even if it is $null: |
− | //set %a Global | var -i | + | //set %a Global | var -i Local1 | echo -a Value1: %a | var -i %a Local2 | echo -a Value2: %a | var %a | echo -a Value3: %a | var -i %a Local3 | echo -a Value4: %a | echo -a $var(%a,1).local / $var(%a,1).value vs $var(%a,2).local / $var(%a,2).value |
returns: | returns: | ||
Value1: Global | Value1: Global | ||
Line 101: | Line 96: | ||
By default, /var and /set do not allow value to be a pair of double quotes nor to end with a single space (multiple spaces can be set) | By default, /var and /set do not allow value to be a pair of double quotes nor to end with a single space (multiple spaces can be set) | ||
The -p changes /var and /set to allow these values: | The -p changes /var and /set to allow these values: | ||
− | //var -p %a "" | var -p %b test $+ $chr(32) | echo -a %a | + | //var -p %a "" | var -p %b test $+ $chr(32) | echo -a %a / $len(%b) |
− | returns: "" | + | returns: "" / 5 |
− | //var %a "" | var %b test $+ $chr(32) | echo -a %a | + | //var %a "" | var %b test $+ $chr(32) | echo -a %a / $len(%b) |
− | returns: | + | returns: / 4 |
-p also includes -n blocking of math operation: | -p also includes -n blocking of math operation: | ||
//var -p %a 1 + 1 | echo -a %a | //var -p %a 1 + 1 | echo -a %a | ||
Line 111: | Line 106: | ||
<syntaxhighlight lang="mIRC"> | <syntaxhighlight lang="mIRC"> | ||
The = is no longer required, and is a difference in behavior between /set and /var, though it makes it easier to make a local var beginning with the = symbol: | The = is no longer required, and is a difference in behavior between /set and /var, though it makes it easier to make a local var beginning with the = symbol: | ||
− | //set %a = testa | set %b = = testb | echo -a | + | //set %a = testa | set %b = = testb | echo -a %a / %b |
− | //var %a = testa | var %b = = testb | echo -a | + | //var %a = testa | var %b = = testb | echo -a %a / %b |
Return: | Return: | ||
− | + | = testa / = = testb | |
− | + | testa / = testb</syntaxhighlight> | |
By default, /var and /set do not allow value to be a pair of double quotes nor to end with a single space (multiple spaces can be set) | By default, /var and /set do not allow value to be a pair of double quotes nor to end with a single space (multiple spaces can be set) | ||
<syntaxhighlight lang="mIRC"> | <syntaxhighlight lang="mIRC"> | ||
The -p changes /var and /set to allow these values: | The -p changes /var and /set to allow these values: | ||
− | //var -p %a "" | var -p %b test $+ $chr(32) | echo -a | + | //var -p %a "" | var -p %b test $+ $chr(32) | echo -a %a / $len(%b) |
− | //var %a "" | var %b test $+ $chr(32) | echo -a | + | //var %a "" | var %b test $+ $chr(32) | echo -a %a / $len(%b) |
Return: | Return: | ||
− | + | "" / 5 | |
− | + | / 4</syntaxhighlight> | |
== Compatibility == | == Compatibility == |