From WikiChip
mirc/commands/set
< mirc‎ | commands
Revision as of 17:53, 2 July 2014 by 83.204.132.94 (talk)

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