Well, to start, you seem to be mixing up the scope of variables. So... a lesson in variables:
All programming languages have methods for placing values into memory. You reserve a place in your computer's memory by declaring your intention and assigning the location a label. In Visual Basic Script, it is done like this:
Some programming languages allow you to declare a new variable on the fly, simply by assigning a value. For example:
Now, programming languages usually also have different scopes for variables. This allowance is done so that software can be more efficient, and also to reduce conflicts. Variables (memory) can be allocated only when needed, then released when it is no longer required.
One example, is the Global or Public variable. This is a variable (memory location) that persists for the entire time that your program is running. In Visual Basic Script, there are two ways to declare a variable as Public:
Dim MyVariable
Sub MySubroutine
MyVariable = "TestValue"
End Sub
Notice that the Dim statement is declared outside of any subroutine. Declaring a subroutine in the 'mainline' of your script means that any subroutine can interact with that variable.
Sub MySubroutine
Public MyVariable
MyVariable = "TestValue"
End Sub
This is the other way, which is to explicitly declare you want the variable to be global to your entire program, by using the Public directive instead of the Dim directive.
Now, the other type of variable is the procedural, local, Private variable. This type of variable is allocated inside a subroutine, and it only persists while the subroutine is running. In Visual Basic Script, this is accomplished like this:
Sub MySubroutine
Dim MyVariable
MyVariable = "TestValue"
End Sub
...or...
Sub MySubroutine
Private MyVariable
MyVariable = "TestValue"
End Sub
In these cases, the declaration of the variable reserves some memory, but only while your subroutine is executing. Once the 'End Sub' line is processed, any local values are tossed as the memory is released.
Ok... following all that? In terms of using VBS under MUSHclient, you should know that any Global/Public resources will remain in memory while your 'World File' is open. If you close your 'World File', Global/Public resources are released/forgotten.
For some people, this would be catastrophic. Fortunately, Nick, the author of MUSHclient, has provided an interface by which you can create a third level of variables. You (as a programmer) can tell MUSHclient to store variables for you. MUSHclient will save these variables to a file when you close the 'World File', so your values will still persist from session to session. In Visual Basic, this interaction is done like this:
World.SetVariable "MyVariable", "TestValue"
World.Note World.GetVariable("MyVariable")
World.DeleteVariable "MyVariable"
Notice that are not required to initialize (reserve a memory location for) the MUSHclient variable using a specific directive. Your MUSHclient variable is initialized on-the-fly when you assign the value.
For purposes of efficiency, I recommend you not use MUSHclient variables unless you explicitly require that the values be stored from session to session. You should be mindful of allocating resources carelessly. Efficiently written script will run faster. |