You need to think of the language and of MUSHclient as seperate beasts. In this case, your confusion simply lies in understanding where MUSHclient begins, and Lua ends.
This is complicated by the fact there are basically two ways to use scripts in MUSHclient; and I'll go over them briefly.
The 'easy' way is to use the 'Send To: [Script]' option, and input your script in the 'Send:' box. I call it easy because it is quick to use. However, MUSHclient also does some fancy things like substitute things like %1 or (if expand variables is checked) @hp into their contents, and this often leads to confusion with new scripters:
if @person == "Marcus" then Note("It's Marcus.") end
gets translated to
if Marcus == "Marcus" then Note("It's Marcus.") end
which means it is interpreted as a variable... which Lua does not throw errors on, but substitutes with nil if they do not exist. Correct is:
if "@person" == "Marcus" then Note("It's Marcus.") end
Long story short: there are pitfalls with that method, and given the fact you are used to a more controlled scripting environment already I advise to avoid this method. (This method is also slower because MUSHclient can't compile the script for obvious reasons and re-use that. But that's a minimal performance hit unless the script gets executed every other line.)
The method I prefer is what I already explained in the other topic you started, where you misunderstood how to use it. Basically you declare a function that takes certain inputs in your script file, and you tell MUSHclient the name of this function inside the trigger/alias/timer Script: box. When this script needs executing, MUSHclient simply tells the scripting engine to call that function; it can't be any simpler nor faster from MUSHclient's side.
Now to answer your question about scope...
Scope depends on the language, and how the language deals with this. Lua can be complicated with scopes, but the MUSHclient way is simple: there is a global scope, and all variables (functions are variables of the function type!) are declared in that.
So whenever MUSHclient does something, you need to imagine it as MUSHclient picking off from the bottom of the script you have loaded. An even better idea is an interactive terminal like Lua and Python offer; except MUSHclient is the one typing the new lines.
You do not need to worry about garbage collection unless you let your script run for months on end, and it litters very much in the global script space (think thousands of variables). And if that is the case, you may need to put such information in a separate table which you can easily clear out when the time comes.
If you are a clean coder, you'll figure out conventions and a consistency that works well for you. In Lua, always use the 'local' specifier unless you definitely need the information at a later stage.
Sorry for the long-windedness... but I hope it helps you out. :-) |