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 ➜ Temporarily disabling one trigger

Temporarily disabling one trigger

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


Posted by Caelen   (81 posts)  Bio
Date Thu 08 Jul 2010 06:03 AM (UTC)

Amended on Thu 08 Jul 2010 06:06 AM (UTC) by Caelen

Message
I found a part of the help files that mentions a trigger enable/disable script.

Script function

world.EnableTrigger

Type

Method

Summary

Enables or disables a trigger

Prototype

long EnableTrigger(BSTR TriggerName, BOOL Enabled);

I don't understand how it's supposed to be used at all though. I'd like to make an alias that lets me temporarily disable one of my anti-theft triggers so I can access my gold for shopping, preferably one that will take only a certain amount of gold out and then immediately re-enable the trigger as well.

Any ideas?

Edit: I did find that other thread about disabling all scripting, but that's not what I'm after. :)
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Thu 08 Jul 2010 06:09 AM (UTC)
Message
Give your trigger a name (a.k.a. a label) via the trigger editor, and use that as the first parameter to EnableTrigger(). The second parameter is either true or false, telling it whether to enable it or disable. Example:

EnableTrigger("foolabel", true)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 08 Jul 2010 06:39 AM (UTC)
Message
Another approach is to have a "shopping" alias that sets a variable, eg.


shopping = true


Then in your anti-theft trigger (which you leave enabled) test it, eg.


if not shopping then
  Send "kill thief"
else
  shopping = false
end -- if


That is, you react with your anti-theft action if the shopping flag is not set, otherwise you allow this particular action, but then clear the shopping flag, so it only gets allowed once.

- Nick Gammon

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

Posted by Caelen   (81 posts)  Bio
Date Reply #3 on Thu 08 Jul 2010 07:50 AM (UTC)

Amended on Thu 08 Jul 2010 08:00 AM (UTC) by Caelen

Message
Twisol said:

Give your trigger a name (a.k.a. a label) via the trigger editor, and use that as the first parameter to EnableTrigger(). The second parameter is either true or false, telling it whether to enable it or disable. Example:

EnableTrigger("foolabel", true)



So THAT'S what the label is used for! Thanks!

And... truth be told, I like this one better than the shopping variable. I can make one alias like

alias: getsafe * gold
EnableTrigger("mygold", false)
Send "get %1 gold from @pack"
EnableTrigger("mygold", true)


here's hoping I did the code bracket thingy right...

And, I have all of my item numbers stored as variables, so @pack will return the pack's ID number.

Edit:


<aliases>
  <alias
   match="getsafe * gold"
   enabled="y"
   expand_variables="y"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"
wait.make (function ()

 EnableTrigger("mygold", false)
 Send ("get %1 gold from @pack")
 wait.time(0.1)

 EnableTrigger("mygold", true)

end)</send>
  </alias>
</aliases>
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #4 on Thu 08 Jul 2010 07:56 AM (UTC)
Message
Your problem here is that the Send is not instantaneous. You remember "lag"? There is always some, even if it is fairly minor.

What you have done is disable the trigger, send something to the MUD, and enable it again immediately. However the MUD may take a few milliseconds (at least) to respond.

- Nick Gammon

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

Posted by Caelen   (81 posts)  Bio
Date Reply #5 on Thu 08 Jul 2010 08:00 AM (UTC)
Message
Nick Gammon said:

Your problem here is that the Send is not instantaneous. You remember "lag"? There is always some, even if it is fairly minor.

What you have done is disable the trigger, send something to the MUD, and enable it again immediately. However the MUD may take a few milliseconds (at least) to respond.


Yep! *points at the edit* I caught that after my first test.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #6 on Thu 08 Jul 2010 08:07 AM (UTC)
Message
Note that sending over the network is "asynchronous". Once the data is sent, the script resumes doing whatever it was doing, and you can't make any assumptions about whether the server has received the data. The most you can say after Send() returns, really, is "this data will be sent", because it might not have even left your computer yet!

You can do two things: automatically enable the "mygold" trigger after a few seconds, or use a trigger to wait for a line that shows the action was received and occured successfully. With getting gold, you can usually count on "You get X gold sovereigns from your pack.", except you need to handle the case where you don't have any gold too.

Actually, the time-based alternative is a good fallback in case something weird happens and you never get the line you expected.

EDIT: Major ninja...

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Caelen   (81 posts)  Bio
Date Reply #7 on Thu 08 Jul 2010 08:26 PM (UTC)
Message
The final setup:


<variables>
  <variable name="getgold">1</variable>
</variables>

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="Theft"
   match="You get * gold sovereigns from a *"
   send_to="12"
   sequence="100"
  >
  <send>if (GetVariable("getgold")) == "1" then
 Send "touch amnesia"
 Send "stand"
 Send "put money in @gold"
else
 SetVariable ("getgold", "1")
end</send>
  </trigger>
</triggers>

<aliases>
  <alias
   match="getsafe * gold"
   enabled="y"
   expand_variables="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable("getgold", "2")
Send ("get %1 gold from @gold")</send>
  </alias>
</aliases>


The timer was too finicky, so I went with the altered trigger instead. It does what I want, which is let me get a specific amount of gold with a single alias, or I can use "all" in place of a number to grab all of it.

Thanks for the help!
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.


18,639 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.