Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Calling aliases from scripts

Calling aliases from scripts

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Gaem   (10 posts)  Bio
Date Sun 04 Feb 2007 11:13 PM (UTC)
Message
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
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 05 Feb 2007 (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gaem   (10 posts)  Bio
Date Reply #2 on Mon 05 Feb 2007 07:23 AM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Mon 05 Feb 2007 06:36 PM (UTC)
Message
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).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gaem   (10 posts)  Bio
Date Reply #4 on Mon 05 Feb 2007 08:07 PM (UTC)
Message
Thanks!
Exactly what I was looking for.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


14,803 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.