From WikiChip
Difference between revisions of "mirc/commands/set"
< mirc‎ | commands

(Created page with "The '''/set command''' can be used to replace the value of an existing variable or create a new variable and assign it the given value. By default /set creates global variable...")
 
Line 1: Line 1:
The '''/set command''' can be used to replace the value of an existing variable or create a new variable and assign it the given value. By default /set creates global variable, this can be changed via the -l switch. The set command can perform one math operation via one of the arithmetic operators: addition (+), subtraction (-), multiplication (*), division (/), and modulo (%). They <em>must</em> 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. Unlike the [[/var command - mIRC|/var]] command, set cannot assign a value to multiple variables at once.
+
The '''/set command''' can be used to replace the value of an existing variable or create a new variable and assign it the given value. By default /set creates global variable, this can be changed via the -l switch. Unlike the [[/var command - mIRC|/var]] command, set cannot assign a value to multiple variables at once. It support [[Variables - mIRC#Math_Operations|one math opearation]]
  
 
== Set evaluation routine ==
 
== Set evaluation routine ==
Line 7: Line 7:
  
 
Will create a variable like %1209425041 with the value of 'ABC'; Similarly this can be used with $nick and $chan in on events.
 
Will create a variable like %1209425041 with the value of 'ABC'; Similarly this can be used with $nick and $chan in on events.
 +
 +
'''Note''':  /set will fail not to evaluate your variable if you have dynamic parameters before the name, read more [[Variables - mIRC#Special_behaviors_&_quirks|here]]
  
 
== Synopsis ==
 
== Synopsis ==
 
  /set [-suNznelk] <%var> [value]
 
  /set [-suNznelk] <%var> [value]
  /set [-suNznelk] <%var> <number> <+ | - | * | / | %> <number>
+
  /set [-suNznelk] <%var> <number> <+ | - | * | / | % | ^> <number>
  
 
== Switches ==
 
== Switches ==
Line 25: Line 27:
 
* '''[value]''' - The value to assign to the variable
 
* '''[value]''' - The value to assign to the variable
 
* '''<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 five 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
  

Revision as of 16:53, 2 July 2014

The /set command can be used to replace the value of an existing variable or create a new variable and assign it the given value. By default /set creates global variable, this can be changed via the -l switch. Unlike the /var command, set cannot assign a value to multiple variables at once. It support one math opearation

Set evaluation routine

The set command has its own evaluation routine which lets you dynamically concatenate additional values onto the variable name before the assignment takes place.

//set -ls % $+ $ctime ABC

Will create a variable like %1209425041 with the value of 'ABC'; Similarly this can be used with $nick and $chan in on events.

Note: /set will fail not to evaluate your variable if you have dynamic parameters before the name, read more here

Synopsis

/set [-suNznelk] <%var> [value]
/set [-suNznelk] <%var> <number> <+ | - | * | / | % | ^> <number>

Switches

  • -s - Display variable assignment value
  • -uN - Unsets the variable after N amount of seconds. A special case has been made for -u0 which will make the variable unset at the end of script processing, the same way binary variables do.
  • -z - Decreases the value of the variable by 1/second until zero is reached. At zero the variable will be unset.
  • -n - Treat the value as plain text, even if arithmetic operators are used.
  • -e - Unsets the variable when mIRC exists
  • -l - Creates a local variable instead
  • -k - Keeps the unset time (-u) from a previous command

Parameters

  • <%var> - The name of the variable
  • [value] - The value to assign to the variable
  • <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

Example

; /countDown 
Alias countDown {
  ; set some value
  set %var Countdown:
  ; print the value
  echo -a %var
  ; set the value to 3, decrease once per second
  set -zs %var 3
}

Will output:

Countdown:
-
* Set %var to 3
-
* Set %var to 2
-
* Set %var to 1
-
* Unset %var
-

The -u0 switch can be used to create a variable with global scope that will get unset at the end of the script processing. This can be very helpful at times.

Alias example {
  set -u0 %x A
  bb
  ; will print 'B'
  echo -a %x
}
alias bb {
  ; replace the value of %x with B, keep the unset setting
  set -k %x B
}

A simple !seen script that uses /set special evaluation routine to create dynamic variables:

on *:text:!seen &:#mIRC:{
  ; check if the variable is set
  if ($var(seen. $+ $2)) {
    ; notice the user the value of '%seen.<nick>'
    notice $nick I have seen $2 $var(seen. $+ $2, 1).value
  }
  else notice $nick I have not seen $2 anywhere.
}
on *:text:*:#:{
  ; set the value to '%seen.<nick>'
  set %seen. $+ $nick Talking in $chan < $+ $nick $+ > $1-
}

Compatibility

Added: mIRC v4.0

Added On: 20/03/96

Note: Individual switches were not taken into consideration.

See also