Creating an alias to toggle a trigger group on/off

Posted by Darcon on Fri 19 Oct 2012 04:32 AM — 6 posts, 24,573 views.

#0
Hi, I am new to MushClient. I am also new to scripting. I am taking time to learn Lua on my own so I am just in the basics now.

Anyway what I am trying to do is create an alias that will toggle a trigger group from enabled to disabled or visa versa.

Here what I have so far. I created an alias called moneyrun and a variable called MoneyRun. I initially set the variable to 1.

The alias is set to send to script. In the send box:

EnableTriggerGroup ("Money Run", GetVariable("MoneyRun"))
if GetVariable("MoneyRun") == 1
then SetVariable("MoneyRun", "0");print("Money Run Enabled") else SetVariable("MoneyRun", "1");print("Money Run Disabled") end

When I initiate the alias, if the variable is set to 0, it will enable the group. When I do it again, it does not disable like it should. What am I doing wrong here? I appreciate any feedback.
#1
I did end up getting the alias to work correctly. I simplified the code and now it works as I intended it to.

EnableTriggerGroup ("Money Run", MoneyRun)
if MoneyRun == 1
then MoneyRun = 0
print("Money Run Enabled")
else MoneyRun = 1
print("Money Run Disabled")
end

What I don't understand is that the variable doesn't change in the variable screen of mush client it remains 0 in either state. I don't know why it doesn't but since it seems to be doing what it should be then I don't really care.

If anyone has any input on this or a better way to accomplish this I would appreciate it. Thanks
Australia Forum Administrator #2
See this tutorial about variables:

http://www.gammon.com.au/forum/?id=10863

You have changed a script variable, not a client variable.
Australia Forum Administrator #3

 if GetVariable("MoneyRun") == 1


Client variables are always strings. Thus you should have tested for:


 if GetVariable("MoneyRun") == "1"

#4
Thank you Nick
#5
Ok so now that I know the difference between a script variable and a client variable I rewrote the code once again.

EnableTriggerGroup ("Money Run", GetVariable("MoneyRun"))
if GetVariable("MoneyRun") == "1"
then SetVariable("MoneyRun", "0")
print("Money Run Enabled")
else SetVariable("MoneyRun", "1")
print("Money Run Disabled")
end

As expected, it worked perfectly and now the client variable is actually reflecting the state of the variable. Thank again for your help Nick.