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
➜ Creating a variable that can be constantly changed and added to
|
Creating a variable that can be constantly changed and added to
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Spetz
(8 posts) Bio
|
| Date
| Sun 13 Feb 2011 07:35 PM (UTC) |
| Message
| 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
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Sun 13 Feb 2011 09:17 PM (UTC) |
| Message
| 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)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Spetz
(8 posts) Bio
|
| Date
| Reply #2 on Mon 14 Feb 2011 07:19 PM (UTC) |
| Message
| 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>
| | Top |
|
| Posted by
| Spetz
(8 posts) Bio
|
| Date
| Reply #3 on Mon 14 Feb 2011 08:59 PM (UTC) |
| Message
| 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. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Mon 14 Feb 2011 11:36 PM (UTC) |
| Message
| 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")
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Spetz
(8 posts) Bio
|
| Date
| Reply #5 on Tue 15 Feb 2011 07:03 PM (UTC) |
| Message
| | Wow... For some reason I never thought to just use 1 trigger. Thanks for the help I have modified it and it works beautifully. | | 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,505 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top