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 (%), bitwise-and (&), 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.
+
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 [-sgnip] <%var> [[= ]value]
+
  /var [-sg] <%var> [[= ]value]
 
  /var [-sg] <%var> <number> <+ | - | * | / | %> <number>
 
  /var [-sg] <%var> <number> <+ | - | * | / | %> <number>
  /var [-sg] <%var> [= ]<number> <+ | - | * | / | % | &> <number>
+
  /var [-sg] <%var> [= ]<number> <+ | - | * | / | %> <number>
 
  /var [-sg] <%var> [[= ]value][, <%var> [[= ]value]][, ...]
 
  /var [-sg] <%var> [[= ]value][, <%var> [[= ]value]][, ...]
  /var [-sg] <%var> [= ]<number> <+ | - | * | / | % | &> <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 seven possible arithmetic operations
+
* '''<+ |''' - | * | / | % | ^ > - 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
 
'''Note''': if your [value] ends with a literal space seperated comma, mIRC will see it as a new variable assignement even if no '%' is found, you need to use two commas to produce one in this case: //var %a test ,,
 
  
 
== 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 %b 7 , %c 11 , %a %b & %c | echo -a a= %a b= $base(%b,10,2) c= $base(%c,10,2) b&c= $and(%b,%c)
 
returns: 3 because bit-1 and bit-2 are the only common bits between 7 and 11
 
 
//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 $null. "/var %a" does not unset the local var, it sets it to $null:
+
-i causes /var to act only if local var does not exist, even if it is $null:
//set %a Global | var -i %a 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
+
//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 vs $len(%b)
+
//var -p %a "" | var -p %b test $+ $chr(32)  | echo -a %a / $len(%b)
returns: "" vs 5
+
returns: "" / 5
//var    %a "" | var    %b test $+ $chr(32)  | echo -a %a vs $len(%b)
+
//var    %a "" | var    %b test $+ $chr(32)  | echo -a %a / $len(%b)
returns: vs 4
+
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 1. %a vs %b
+
//set %a = testa | set %b = = testb | echo -a %a / %b
//var %a = testa | var %b = = testb | echo -a 2. %a vs %b
+
//var %a = testa | var %b = = testb | echo -a %a / %b
 
Return:
 
Return:
1. = testa vs = = testb
+
= testa / = = testb
2. testa vs = testb</syntaxhighlight>
+
  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 1. %a vs $len(%b)
+
//var -p %a "" | var -p %b test $+ $chr(32)  | echo -a %a / $len(%b)
//var    %a "" | var    %b test $+ $chr(32)  | echo -a 2. %a vs $len(%b)
+
//var    %a "" | var    %b test $+ $chr(32)  | echo -a %a / $len(%b)
 
Return:
 
Return:
1. "" vs 5
+
"" / 5
2. vs 4</syntaxhighlight>
+
/ 4</syntaxhighlight>
  
 
== Compatibility ==
 
== Compatibility ==

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)