Scope

From Scriptwiki
Revision as of 19:48, 3 October 2009 by Aca20031 (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Scope is the term used to refer to a variable's "life-span". mIRC variables have only two scopes.

Global Scope

A variable with a global scope is accessable everywhere in mIRC where a variable can be used. This means in the command line, in every script file, alias file, popup, etc. These variables are saved in the Variables tab of the mIRC Scripts editor (alt+r) which are saved to a file (usually vars.ini).

  • A global scoped variable is created with set and destroyed with unset

Example

Suppose the following was called, /test and then /test2.

alias test {
 set %foo bar.
; %foo is available here
}
alias test2 {
 set %bar foo
 ; %foo is available here after being set with /test
}


%foo will now return bar EVERYWHERE.

Local Scope

A variable with a local scope is only available within the event, alias, or menu (popup) script in which it is used.

  • A local variable is created with var and is automatically destroyed after leaving scope (exiting the current alias, event or menu).

Example

Suppose the following was called using /test

alias test {
 set %foo bar.
; %foo is available here
test2 %foo
}
alias test2 {
 set %bar foo
 ; %foo is NOT available here. We can, however, use $1 to refer to %foo because it was passed as a parameter to the alias.
}


See Also

  • var - Command used to create a local variables
  • Local Variables - Variables with limited scope
  • set - Command used to create global variables