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 ➜ AddTriggerEx and AddAlias

AddTriggerEx and AddAlias

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


Posted by Jenasta   (4 posts)  Bio
Date Thu 14 Jan 2010 03:10 AM (UTC)

Amended on Thu 14 Jan 2010 03:48 AM (UTC) by Jenasta

Message
Is there a similar function to AddTriggerEx, that allows me to specify where the output for my alias is sent to? AddAlias automatically sends to the world window, however I need to have it store to a variable, and then send a message to output. Something like this, although the syntax is horrible, I think it conveys my intent.

AddAlias("set_attack_alias", "^setattack (.*) , (.*)$", (attack_alias = %1)(attack_type = %2) "You have set your alias to" %1 , "And you have set your attack type to" %2, alias_flag.Enabled + alias_flag.RegularExpression + alias_flag.IgnoreAliasCase, "")


I could use SetAliasOption, however I would then have to write a function that checks for the alias, and then if it exists, modify it, which seems like entirely too much code, when the flag for triggers exists.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Thu 14 Jan 2010 03:17 AM (UTC)
Message
I don't see why you couldn't use AddAlias() and SetAliasOption() at the same spot, to be honest. AddAliasEx would be nice, though.

If all else fails, you can use ImportXML() and get the full range of options at the XML level.

'Soludra' on Achaea

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

Posted by Jenasta   (4 posts)  Bio
Date Reply #2 on Thu 14 Jan 2010 03:46 AM (UTC)

Amended on Thu 14 Jan 2010 03:48 AM (UTC) by Jenasta

Message
Your essentially right, I'll just throw them into a function.
My next question is how do I set the variables? Can I do a SetAliasOption() and change send to variable? Whats they syntax for that?

SetAliasOption("set_beetle_attack_alias", "send_to", 9)

However, where do I specify the variable to send TO, and the part of the wildcard I want to send?

I tried:


SetAliasOption("set_beetle_attack_alias", "send_to", sendto.variable(beetle_attack_alias))

But mush wants the 9, and not the sendto.variable

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

Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #3 on Thu 14 Jan 2010 03:48 AM (UTC)

Amended on Thu 14 Jan 2010 03:50 AM (UTC) by Twisol

Message
Two SetAliasOption()s:

SetAliasOption("set_beetle_attack_alias", "send_to", "9")
SetAliasOption("set_beetle_attack_alias", "variable", "beetle_attack_alias")


Remember that in the GUI, Send To and Variable are separate text boxes. As for the text to add to the variable, you put that in ResponseText for AddAlias, which is basically the same as the Send box.

'Soludra' on Achaea

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #4 on Thu 14 Jan 2010 04:22 AM (UTC)
Message
If you are using Lua, you may find the addxml.lua module does exactly what you want. Effectively you can use ImportXML (as Twisol said) to add things, exactly the same way the client does when it reads in your world file, and thus all options are available. However the addxml module simplifies using that.

Template:post=7123 Please see the forum thread: http://gammon.com.au/forum/?id=7123.

- Nick Gammon

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

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #5 on Thu 14 Jan 2010 04:33 AM (UTC)
Message
I don't know why I hadn't heard about that module before. Very cool!

'Soludra' on Achaea

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #6 on Thu 14 Jan 2010 05:03 AM (UTC)
Message
This page tries to summarize that sort of stuff:

http://www.gammon.com.au/modules

- Nick Gammon

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

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #7 on Thu 14 Jan 2010 05:04 AM (UTC)
Message
Yeah, I took a look around to see what else I was missing. Good stuff!

'Soludra' on Achaea

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

Posted by Jenasta   (4 posts)  Bio
Date Reply #8 on Thu 14 Jan 2010 08:49 AM (UTC)

Amended on Thu 14 Jan 2010 08:55 AM (UTC) by Jenasta

Message
Okay, we are making progress, I used the addxml to create the triggers instead of AddTriggerEx(), I do prefer the method, its easier to read, as well as work with. The only problem I'm having now is of lexical scope. In the send line of the trigger, which is sending to a variable(MushClient var), and I'm trying to increment the variable by one, and store it into the variable.
This only sets the variable to one. It seems as if I'm storing the result into a diffrent variable than the variable I created with SetVariable.

SetVariable("beetle_in_room", 0)

addxml.trigger {  match = "^(A carrion beetle enters, scavenging for flesh.|The faint clicking of insect legs on stone alerts you to the entrance of a carrion beetle.|A carrion beetle scuttles in, searching for food.)$", 
                name = "beetle_enter",
                enabled = true,
                regexp = true,
				send_to = 9,
				variable = "beetle_in_room",
                send = (GetVariable("beetle_in_room") + 1),
				sequence = 50,
              }


I tried changing the send line to the following, but it actually returns zero...

send = SetVariable("beetle_in_room", GetVariable("beetle_in_room") + 1),
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #9 on Thu 14 Jan 2010 09:51 AM (UTC)
Message
I think your problem here is that the adding is done when you *create* the trigger, not when you *execute* it.

The simple solution is to just make a trigger that does "send to script" (not send to variable) and in the script do something like what you had:


SetVariable("beetle_in_room", GetVariable("beetle_in_room") + 1)


Now this script executes every time the trigger matches, and will add to the variable each time.

- Nick Gammon

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

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #10 on Thu 14 Jan 2010 05:55 PM (UTC)
Message
In other words, something like this:


SetVariable("beetle_in_room", 0)

addxml.trigger {  match = "^(A carrion beetle enters, scavenging for flesh.|The faint clicking of insect legs on stone alerts you to the entrance of a carrion beetle.|A carrion beetle scuttles in, searching for food.)$", 
                name = "beetle_enter",
                enabled = true,
                regexp = true,
                send_to = 12,
                send = [[SetVariable(GetVariable("beetle_in_room") + 1)]],
                sequence = 50,
              }


The double-brackets around the send text is actually just another form of quoting, like "" and ''. The send text is supposed to be text, after all - it's evaluated and executed once the trigger is fired. And the send_to is 12, which means Script.

'Soludra' on Achaea

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #11 on Thu 14 Jan 2010 10:43 PM (UTC)
Message
And indeed, you can replace 12 by sendto.script these days.
That is:


send_to = sendto.script,


That makes it better self-documenting.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


35,703 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.