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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Quirky aliases & triggers that fire them

Quirky aliases & triggers that fire them

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


Posted by Aidyn.Hartfire   USA  (15 posts)  [Biography] bio
Date Fri 18 Jul 2008 03:31 AM (UTC)
Message
Alright, here is the problem, I have made a small set of triggers to handle forging in Lusternia. Along with all of the variables and aliases to handle it. The issue is that aliases entered into the triggers don't seem to function. At least, they won't work when called up automatically, but when I enter them in manually they work perfectly. Even the triggers passes testing. I just don't know why. Here is an example:

<triggers>
<trigger
expand_variables="y"
group="Forging"
ignore_case="y"
match="Damage: * Precision: * Speed: *"
send_to="12"
sequence="100"
>
<send>if %1 < @min_damage then
SetVariable ("reforge", "on")
SetVariable ("next", "on")
Send ("reforge")
elseif %2 < @min_precision then
SetVariable ("reforge", "on")
SetVariable ("next", "on")
Send ("reforge")
elseif %3 < @min_speed then
SetVariable ("reforge", "on")
SetVariable ("next", "on")
Send ("reforge")
end -- if</send>
</trigger>
</triggers>



Like I said, the problem is that it won't reference the aliases properly. More specifically, it acts as if the alias doesn't exist at all or that the syntax is incorrect for the alias being called, but when I enter the alias manually it does the action it is supposed to perform. Am I not doing that part correctly? I have done Send ("wazzamazoo")plenty of times before in other triggers and it works. Maybe there is an option I don't have selected? This code seems to be pretty solid based on what I have seen from search results. Again, it is probably some amateur mistake that I over-looked. Thanks for any input.


if me = "confused" then
SetVariable ("idiot", "yes")
Send ("choke")
DoAfter (3, "curse")
else Send ("fist pumpage")
end -- if
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #1 on Fri 18 Jul 2008 07:51 AM (UTC)
Message
Send() sends stuff directly to the mud.

To run something through the command processor, and have it check for Aliases and such, use Execute() instead.
[Go to top] top

Posted by Aidyn.Hartfire   USA  (15 posts)  [Biography] bio
Date Reply #2 on Fri 18 Jul 2008 06:10 PM (UTC)
Message
I'll give it a shot. Just some questions for problems I can see myself running into. Is the syntax the same for Execute as it is for Send (I know I can look this up later, but sometimes the Help files aren't extremely clear on the differences). Also, don't I want it to send it directly to the MUD? Or do you mean that Send () would be better for doing unaliased actions, such as every step that "reforge" would do? For example:

The alias "reforge" sends all of the following commands--'put armour in forge,' 'smelt armour,' take commodities from forge' forge for design.'

So, if I get the gist of this, Send () is better to directly assert those to the MUD itself, because they are preprogrammed actions; whereas, Execute () would be best to reference the alias because it holds a series of actions I have determined? Is that correct?

Perhaps it would be faster for the string of actions if I just designated exactly what I wanted to do in the trigger instead of sending it searching through aliases for the one that matches. Anyhow, thanks for the input, again Wortstje.

if me = "confused" then
SetVariable ("idiot", "yes")
Send ("choke")
DoAfter (3, "curse")
else Send ("fist pumpage")
end -- if
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 18 Jul 2008 08:54 PM (UTC)
Message
Yes the syntax is the same, see:

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

A slight difference is that Send lets you supply multiple arguments which it concatenates, whereas Execute doesn't, however you can always concatenate them yourself, if you need to.

In general, if the thing you are sending might be an alias, you may as well use Execute rather than Send. In your case:


Execute ("reforge")


There would be a very slight speed penalty, as it checks all aliases, perhaps 0.01 seconds or less. I wouldn't worry about it.

The only thing I would worry about is the possibly unusual case of where you want to send the same thing you matched. For example:


<aliases>
  <alias
   match="quit"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

Send ("say goodbye everyone!")
Send ("quit")

</send>
  </alias>
</aliases>


In this case, if you changed Send ("quit") to Execute ("quit") then the same alias would match again, it would send "say goodbye everyone!" to the MUD, try to quit again, re-match the alias, and thus go into a loop. MUSHclient does detect such attempts, and if you check the result from Execute you would see this:


Run-time error
World: smaug 2
Immediate execution
[string "Alias: "]:2: Calls to "Execute" nested too deeply



Quote:

Perhaps it would be faster for the string of actions if I just designated exactly what I wanted to do in the trigger instead of sending it searching through aliases for the one that matches.


Don't bother doing that - too complicated and you won't notice the speed difference.

- Nick Gammon

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

Posted by Aidyn.Hartfire   USA  (15 posts)  [Biography] bio
Date Reply #4 on Fri 18 Jul 2008 09:38 PM (UTC)
Message
Alright thanks! A bit off topic, but is there a definitive post about the extent to which if/or/then/else statements can be used? That is, one that lists all of the appropriate functions and how to use them? The reason being is that in this same set of triggers, there are two triggers that fired as a result of two prompts sent by one action. For example, "Physical cutting: 85," and "Physical blunt: 90," fires a trigger for each, but is caused by one action. I was thinking of having the first prompt set a variable, then referencing that variable in the second trigger. That way, it doesn't send the "reforge" alias twice. Which hasn't been a problem yet, but could be. I have had things destroyed before when a command was entered to forge something while something was already being forged. Annoying and expensive. The end result should be, in theory, something to the effect of:

if @stat_cut < @min_cut or %1 < @min_blunt then
Execute ("reforge")
end--if


Not an extensive example, but you get the idea. Basically, I want to know how I can do math functions or at least evaluate multiple integers before executing the solution.

if me = "confused" then
SetVariable ("idiot", "yes")
Send ("choke")
DoAfter (3, "curse")
else Send ("fist pumpage")
end -- if
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sun 20 Jul 2008 02:51 AM (UTC)
Message
Certainly you can, and for simplicity I recommend simply using Lua variables, rather than MUSHclient ones. The reason is it is simpler and slightly faster. Plus Lua variables can be strings, numbers, booleans etc.

The sort of thing you might do is:


if %1 < @min_blunt and
  not doing_reforge then
  Execute ("reforge")
  doing_reforge = true
end -- if


This stops it being cast twice, and then when you know the reforge is finished (another trigger no doubt) you can do:


doing_reforge = false


- Nick Gammon

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


14,876 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 HostDash]