Using Variables

Posted by Burzmali on Thu 21 Dec 2006 08:27 PM — 5 posts, 22,597 views.

#0
I am having no luck trying to use variables. I have v3.83. When I try to send to the following to script from an alias

setvariable ("clevel", "82") I get the following error.

[string "Alias: "]:3: attempt to call global 'setvariable' (a nil value)
stack traceback:
[string "Alias: "]:3: in main chunk

I went to the Variables area and entered the variable clevel with the contents 82 but it made no difference. The sanbox seems to be set up the way you describe in the thread improved sandbox (if that is even relevent). If i send the alias to execute it doesn't process the if statement it just sends each line in the alias to the mud 1 line at a time. I am obviously missing something fundamental again. what I am ultimately trying to accomplish is to create an alias which will choose which speedwalk will be sent to the mud based on what level the character is.
Australia #1


setvariable should be SetVariable

The caps thing, try that for starters.
#2
Ok, that was the problem alright. Now, i have entered the variable clevel in the variables section with the value of 82. I am assuming that makes it a global variable. My alias is as below entered directly into the edit window:

local mylevel
GetVariable ("mylevel", "clevel")
Send ("enter")
Send ("d")
if mylevel < 60 then
Send ("run d2s10wn2wn4wn8wn21w11sd")
else
Send ("rem (255326)")
Send ("get warplans (249550)")
Send ("wear warplans")
Send ("enter")
Send ("rem warplans")
Send ("put warplans (249550)")
Send ("wear (255326)")
end

when i call the alias i get the following error:

[string "Alias: "]:5: attempt to compare nil with number
stack traceback:
[string "Alias: "]:5: in main chunk

i also tried it with tonumber (mylevel) and got the same result. Why would mylevel be nil and is it possible just to refer to the global variable directly? The help is greatly appreciated.
Australia Forum Administrator #3
Have a look at the documentation for GetVariable. The examples there should help:

http://www.gammon.com.au/scripts/doc.php?function=GetVariable

You want:


local mylevel = GetVariable ("clevel")


That is, assigning the MUSHclient variable "clevel" into the script variable "mylevel".
#4
Thanks, that got it working.