Creating a variable that can be constantly changed and added to

Posted by Spetz on Sun 13 Feb 2011 07:35 PM — 6 posts, 19,505 views.

#0
I have been trying to make a trigger that will add someone to my auto rescue list and then tell the group that they have been added. Unfortunately i do not know much about scripting and have spent the last couple hours cruising the forums to try to figure this out.

So far I have made 2 triggers.

<triggers>
<trigger
enabled="y"
ignore_case="y"
match="^(.*?) tells the group \'add me\'$"
regexp="y"
sequence="100"
>
<send>; |br|%1 |n|has been added to |by|autorescue</send>
</trigger>
</triggers>


That one works. All it does is auto respond the the group saying that I have added them to autorescue. (the |br| and |by| are colors.

the next one is:

<triggers>
<trigger
enabled="y"
expand_variables="y"
ignore_case="y"
keep_evaluating="y"
match="^(.*?) tells the group \'add me\'$"
regexp="y"
send_to="9"
sequence="100"
variable="group"
>
<send>|%1</send>
</trigger>
</triggers>


This changes the variable... but instead of adding someone it just replaces what I already have.

For example:

John tells the group 'add me'
the variable changes to |John

This is also is a problem since the first name should not have a | (divider symbol) in front of it. I can simply manually add a name at the beginning, but that defeats the purpose of having a trigger in the first place.

Moving on:

Frank tells the group 'add me'
variable changes to |Frank instead of John|Frank
Australia Forum Administrator #1
You need a little bit of scripting, at the least. Concatenating variables isn't part of the GUI interface per se.

One approach is to simply add to the end of a variable. Use "send to script" and in the script do something like this:


SetVariable ("group", GetVariable ("group") .. "|%1")


That will tack on the vertical bar, followed by the player's name, to the current group, and save it back as the group variable.

To handle not having the bar for the first time someone uses the trigger, you could do this:


local group = GetVariable ("group")  -- get into Lua variable

-- if not empty, add the vertical bar
if group ~= "" then
  group = group .. "|"
end -- if

-- now add the player
group = group .. "%1"

-- put back into MUSHclient variable
SetVariable ("group", group)


#2
I tried this and it is adding to the end of the variable like I wanted, but instead of the name it just adds %1.

Looks like this:
John|%1 instead of John|Frank

I know the problem is that I am not matching the wildcard correctly and I am not sure how to fix it. Here is what it looks like so far.


<triggers>
<trigger
enabled="y"
ignore_case="y"
match="^(.*?) tells the group \'add me\'$"
name="addme"
regexp="y"
send_to="12"
sequence="100"
variable="group"
>
<send>SetVariable ("group", GetVariable ("group") .. "|%1")</send>
</trigger>
</triggers>


#3
So after playing around for a while longer I tried changing it from a regular expression to a normal expression:

* tells the group 'add me'

This worked... But now my previous trigger(the one that informs the individual that they have been added to autorescue) does not work. This makes me think that I can only have 1 trigger matching an output from the mud and the one higher in the list is the one that executes. Except that earlier I was getting the first trigger to work and the second one returned the %1 (as stated in above post). Not sure why this happens, but I finally solved my problem by changing both of the triggers to plain expressions instead of regular expressions.

They work great now! Here they are if you are interested. And thanks for the help and the speedy response Nick.


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   keep_evaluating="y"
   match="* tells the group 'add me'"
   name="addme"
   send_to="12"
   sequence="100"
   variable="group"
  >
  <send>SetVariable ("group", GetVariable ("group") .. "|%1")</send>
  </trigger>
</triggers>


and


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   keep_evaluating="y"
   match="* tells the group 'add me'"
   sequence="100"
  >
  <send>; |br|%1 |n|has been added to |by|autorescue</send>
  </trigger>
</triggers>


Again the |br| |n| and |by| in the second trigger are just colors for my mud and have nothing to do with the script. (Just to keep this less confusing).

Also I apologize for not using the code box earlier as this was my first postings and I did know how at that time.

Thanks again.
Australia Forum Administrator #4
Regular expressions should work, but the important part for you was to check "keep evaluating" otherwise only one matches.

But rather than have two triggers matching the same thing (which you always have to keep in step) you can make one trigger do more things, like:


SetVariable ("group", GetVariable ("group") .. "|%1")
Send ("; |br|%1 |n|has been added to |by|autorescue")

#5
Wow... For some reason I never thought to just use 1 trigger. Thanks for the help I have modified it and it works beautifully.