Your concept of local and global is basically correct, but we should be careful because there are local and global variables inside the Lua script itself and there are also local and global variables with respect to working between multiple different scripts. The best way we have to verbally differentiate between them is to refer to "script" variables and "MUSHclient" variables. The MUSHclient variables are the ones that will let you talk between your aliases and triggers. For your purposes the Lua script local and global variable difference doesn't matter, and you only care about the script vs MUSHclient variable difference.
Lua script variables are like your gopath.
MUSHclient variables are set with SetVariable("variable_name", "variable_value") and read with GetVariable("variable_name")
Unfortunately MUSHclient does not automatically convert complex types like tables into strings and back when you use SetVariable and GetVariable, so that part becomes manual.
But you can, for example, create a MUSHclient variable named gopath with the value
nw,nw,nw,n,n,e,e,e,se,se,sw,s,sw
Note, it is important here that I used only commas between the steps and no quotation marks or spaces.
And you can have another MUSHclient variable called gopath_step with the value
And then in a trigger or alias you can do
script_gopath = utils.split(GetVariable("gopath"), ",") -- read the comma-separated path from the MUSHclient variable and split it into components
script_gopath_step = tonumber(GetVariable("gopath_step")) -- read the current step number along the path
script_current_step = script_gopath[script_gopath_step] -- pick the step from the path for that step number
if script_current_step then
Send(script_current_step) -- if there's a next step, move in that direction
end
SetVariable("gopath_step", script_gopath_step + 1) -- add 1 to the step number so that we do the next step next time
That would do the next step in the sequence, whatever it happens to be.
Earlier in the thread I mentioned two triggers for moving to the next room. That's how you would do the movement in those triggers. No loops involved. |