AddTriggerEx and AddAlias

Posted by Jenasta on Thu 14 Jan 2010 03:10 AM — 12 posts, 37,576 views.

#0
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.
Amended on Thu 14 Jan 2010 03:48 AM by Jenasta
USA #1
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.
#2
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

Amended on Thu 14 Jan 2010 03:48 AM by Jenasta
USA #3
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.
Amended on Thu 14 Jan 2010 03:50 AM by Twisol
Australia Forum Administrator #4
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.
USA #5
I don't know why I hadn't heard about that module before. Very cool!
Australia Forum Administrator #6
This page tries to summarize that sort of stuff:

http://www.gammon.com.au/modules
USA #7
Yeah, I took a look around to see what else I was missing. Good stuff!
#8
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),
Amended on Thu 14 Jan 2010 08:55 AM by Jenasta
Australia Forum Administrator #9
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.
USA #10
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.
Australia Forum Administrator #11
And indeed, you can replace 12 by sendto.script these days.
That is:


send_to = sendto.script,


That makes it better self-documenting.