| Message |
Just to clarify for the original poster, plugins are intended to have separate script and variable spaces. This is so that, whether you use MUSHclient variables, or script variables, there is no clash between one plugin and another.
For example, one plugin author might have a variable "count" which is a count of mobs killed, and another one might have a variable "count" which is a count of the times you levelled.
The "main world" file (that is, outside any plugin) is effectively another script and variable space again (so plugins don't clash with non-plugins).
So, in the main world file, or inside a particular plugin, you have two ways of storing and accessing variables:
- MUSHclient variables
- Script-language variables (whatever the language is)
The MUSHclient variables have the advantage you can access them from triggers (like matching on @mobname in a trigger). They are also saved from one session to another, to disk, assuming you save your world file. Plugin variables are saved to disk if you enable the "save state" flag when writing the plugin.
Script language variables on the other hand are easier to use. Compare:
count = count + 1 -- script variable
SetVariable ("count", tonumber (GetVariable ("count")) + 1) -- MUSHclient variable
Also script language variables are not saved to disk unless you take steps to do so. This is called serialization, and often takes the form of converting script variables to MUSHclient variables at the last moment, so they get saved to disk. Then next time the world is opened you have to convert them back.
Moving onto the "local" issue - Lua variables are generally speaking "global" - that is, available to every alias, plugin, or script in general. This means a count of mobs killed you might add to in a trigger, is also accessible in an alias.
However if you use the "local" keyword, then that variable is not stored in the "global environment" and becomes local to the block where it is declared. For example:
This code (if in a trigger or alias script) would not change a variable "x" used "globally" elsewhere. This may well be what you want, if you are just using "x" as a "work" variable.
So, like with many things, it is a case of using the right tool for the job. Local variables have their uses, and MUSHclient variables have their uses too. Choose one that suits what you are trying to do.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|