I would like to propose a 3rd type of variable scope. There are currently GLOBAL and LOCAL, I would like to add CONSTANT. They would actually be Script-level variables defined at the beginning of the script or anywhere outside of an event or alias; free floating. They would be writable and re-writable, but I can't think of a better name besides "constants" for a designation.
Their scope would be akin to the scope of "Alias -l". They would allow for initialization of default script settings, or as an easy method of personalizing a shared script.
For Instance:
A bot script designed to only operate in specified channels, while connected with the specified nickname(s), such that only events from this connection are interpreted by the script.
Example:
; My Simple Bot Script
SET %botnicks Games,Gamez
SET %botchans #games,#cards
Alias -l IsBot return $istok(%botnicks,$me,44)
On *:TEXT:*:%botchans: {
if (!$IsBot) return
xyzzy stuff only the bot would do
}
On me:*:JOIN:*: {
if (!$IsBot) return
set %botchans $addtok(%botchans,$chan,44)
}
On me:*:PART:%botchans: {
if (!$IsBot) return
set %botchans $remtok(%botchans,$chan,44)
}
...
As you can see, because
%botnicks and
%botchans were specified outside of any Event or Alias, they are both declared when the script starts, and they have a captive scope to this script alone (like Alias -l does) so there will be no conflict with other scripts or other global variables.
If a local variable is specified inside an Event or Alias, it would supersede these 'constant' variables, the same way they do with global variables. If a global variable is assigned inside an Event or Alias with a name matching a defined constant, that constant will be written to instead of a true global variable.
The primary gain here is simplicity in variable naming, without having to create cleverly-named global variables that might conflict with other scripts, and easy editing and personalizing of a script that somebody downloads. All the configurable features are right up at the top of the script (or just outside any events or aliases).
Thank you for the consideration, Khaled, as always!
Edit:
Maybe they can be called "Captive Variables" instead of "Constants"?