[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Creating an alias to toggle a trigger group on/off
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Creating an alias to toggle a trigger group on/off

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


Posted by Darcon   (26 posts)  [Biography] bio
Date Fri 19 Oct 2012 04:32 AM (UTC)
Message
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.
[Go to top] top

Posted by Darcon   (26 posts)  [Biography] bio
Date Reply #1 on Fri 19 Oct 2012 05:11 AM (UTC)
Message
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
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Fri 19 Oct 2012 05:35 AM (UTC)
Message
See this tutorial about variables:

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

You have changed a script variable, not a client variable.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 19 Oct 2012 05:36 AM (UTC)
Message

 if GetVariable("MoneyRun") == 1


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


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


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Darcon   (26 posts)  [Biography] bio
Date Reply #4 on Fri 19 Oct 2012 07:45 AM (UTC)
Message
Thank you Nick
[Go to top] top

Posted by Darcon   (26 posts)  [Biography] bio
Date Reply #5 on Fri 19 Oct 2012 08:14 AM (UTC)
Message
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.
[Go to top] 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.


3,387 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]