World.SetVariable won't populate variable list

Posted by Wraithian on Tue 16 Dec 2003 09:14 AM — 3 posts, 14,694 views.

USA #0
I have a script set to activate in a world open event:
 Sub WorldInit ()
World.SetVariable var1, "0"
World.SetVariable Var2, "0"
'etc
End Sub 


The problem is that my lines of variable declarations don't seem to do anything; the variables do not appear at all in the variable list. I've not tried to use them, but my assumption is: not seen, not heard (if it's not there, it can't be used).
What am I doing wrong? Oh, and by the way, option explicit is not set.
Russia #1
I can think of a few things here:

1. Make sure that your WorldInit sub is declared in the corresponding world event field of the Scripting dialogue.

2. Putting parenthesis after the name of a sub that doesn't take any arguments is at the least not needed, at most - illegal. Not entirely sure however, the last time I did it was so long ago that I don't remember what happened.

3. The most likely explanation - World.SetVariable requires a string as a first agrument, e.g.:


World.SetVariable "var1", "0"


the way you do it, the script engine probably looks for an internal variable that holds an argument value, and since 'option explicit' isn't specified, it quietly ignores the entire statement.

Regarding how variables are created in Mushclient - I believe it simply creates them if they don't exist at the time of something refering to them.
Australia Forum Administrator #2
I think Ked's point 3 is correct.

You need to quote the name, eg.


World.SetVariable "var1", "0"

Assuming you don't have a variable (a VBscript variable) called "var1" then the Setvariable call is being passed an empty variant, and is failing the variable-name check, and thus is doing nothing.