Calling aliases from scripts

Posted by Gaem on Sun 04 Feb 2007 11:13 PM — 5 posts, 20,692 views.

#0
Apologies if this has already been asked a lot...

What I want to do is have a script that can call one of two aliases depending on the value of a variable.
I thought of using something like this;

if <variable> == 1 then
Send("do something @target")
else
Send("do something else @target")
end

However, doing this doesn't expand the variable (in this case target) like in a normal Mush alias. How would I do this, so it refers to the variable within the Send command?
(in lua, incidently)

Thanks
Australia Forum Administrator #1
I have deleted your 2nd, almost identical, post. You know you can edit posts?

It would help if you posted the actual alias. Something like this should work, if you use "send to script":


if @variable == 1 then
  Send("do something @target")
else
  Send("do something else @target")
end


You need "expand variables" checked.
#2
Ah, I didn't see the edit thing. Anyway, that's not quite the problem. My usual aliases work fine, and have the expand variable box checked, it's just a problem when I have a send command within a script file. So the alias works fine on it's own, but when I do Send(<alias>) within the script it doesn't work.
Australia Forum Administrator #3
You need to use world.Execute, which re-evaluates what you are doing through the command processor.

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

The reason this isn't done automatically is it might send you into a loop (eg. if an alias "north" sent "north" - for some reason - the program would loop).
#4
Thanks!
Exactly what I was looking for.