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
➜ Lua
➜ Trigger to save to variable
Trigger to save to variable
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Halig
Portugal (123 posts) Bio
|
Date
| Sun 22 Feb 2015 01:21 PM (UTC) |
Message
| Hello. I have another question, cause i manage to put it work only in one situation.
Reorx Bla 106 761 0 0 1205 0
This is the MUD information. How can i save the value, in this case, 761? I know how to save it to a variable. Everything works if the case is that, but if anything changes in that sentence, for example:
Reorx Bla 106 761 0 106 1205 0
It changed the 0 to 106. If that happens, the variable that has the 761 saved, doesn't changed anymore. My trigger is as followed:
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="Reorx Bla (.*) (.*) (.*) (.*) (.*) (.*) (.*)"
regexp="y"
send_to="12"
sequence="100"
>
<send>hours = "%2"
SetVariable("hours", hours)</send>
</trigger>
</triggers> | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 22 Feb 2015 07:53 PM (UTC) |
Message
|
match="Reorx Bla (.*) (.*) (.*) (.*) (.*) (.*) (.*)"
That's a confusing regexp. How about detecting numbers if that's what you want:
match="Reorx Bla (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+)"
Quote:
... the variable that has the 761 saved, doesn't changed anymore.
The variable called "hours"? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Halig
Portugal (123 posts) Bio
|
Date
| Reply #2 on Sun 22 Feb 2015 09:01 PM (UTC) |
Message
| Yes Nick. It was a problem with that. I just seen your answer, but i did it this way:
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="Reorx Bla 106 (.*)"
regexp="y"
send_to="12"
sequence="100"
>
<send>teste = "%1"
firstWord = string.match(teste, "^(%w+)")
SetVariable("hours", firstWord)</send>
</trigger>
</triggers>
And it seems to be working. I'll test what you sayed.
Thank you. | Top |
|
Posted by
| Halig
Portugal (123 posts) Bio
|
Date
| Reply #3 on Wed 25 Feb 2015 12:52 PM (UTC) Amended on Wed 25 Feb 2015 05:20 PM (UTC) by Halig
|
Message
| Hello again. Still have problems with this.
Reorx__________Bla__(.*)__(.*)___(.*)____(.*)____(.*)___(.*)
If you see closely, the spaces between the wildcards are really there. If i don't put them, the trigger doesn't match anythig. My problem besides collecting those numbers it, if let's say the wildcard 3 changes from one to two digits, then the space between the wildcard 3 and 4 changes, if goes from 4 spaces to 3 spaces. How can i collect these changing variables?
Thank you | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #4 on Wed 25 Feb 2015 08:11 PM (UTC) |
Message
| Instead of putting a single space in the regexp, do something like:
\s+
That means "one or more spaces". |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Halig
Portugal (123 posts) Bio
|
Date
| Reply #5 on Wed 25 Feb 2015 08:59 PM (UTC) |
Message
| Hi Nick. Thank you, but i didn't understand. Doing something like this:
Reorx Bla 106(\s+)(.*)(\s+)(.*)(\s+)(.*)(\s+)(.*)(\s+)(.*)
Then i've put this for testing:
a = "%1"
b = "%2"
c = "%3"
d = "%4"
e = "%5"
SetVariable("a", a)
SetVariable("b", b)
SetVariable("c", c)
SetVariable("d", d)
SetVariable("e", e)
Cause i need those variables, and only the b caught anything, and caught the all sentence. | Top |
|
Posted by
| Meerclar
USA (733 posts) Bio
|
Date
| Reply #6 on Wed 25 Feb 2015 10:45 PM (UTC) |
Message
| That's where the less greedy regex Nick used with \d in his very first response is useful. Your .* is capturing the entire line, white space and everything because that's what it's designed to do, you need to use a less greedy expression if you want to pull out the center of a changing string of text. |
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #7 on Thu 26 Feb 2015 06:51 AM (UTC) |
Message
| Exactly.
.* matches everything, including spaces.
Did you not try \d ?
Obviously not judging by your recent post.
I don't make these posts just to amuse myself you know, you are supposed to try out my suggestions. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Halig
Portugal (123 posts) Bio
|
Date
| Reply #8 on Thu 26 Feb 2015 06:58 AM (UTC) |
Message
| Hi Nick. Ofcourse i've tryed what you said, if tried endless ways. I won't come here to ask for help, if i didn't try what you and other people say. That will be making you all loosing time.
Gonna try all, again. | Top |
|
Posted by
| Halig
Portugal (123 posts) Bio
|
Date
| Reply #9 on Thu 26 Feb 2015 07:04 AM (UTC) |
Message
| Reorx Bla 106(\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s+)(\d+)
I've tried like this Nick. And still can't get the variables.
a = "%1"
b = "%2"
c = "%3"
d = "%4"
e = "%5"
f = "%6"
SetVariable("a", a)
SetVariable("b", b)
SetVariable("c", c)
SetVariable("d", d)
SetVariable("e", e)
SetVariable("f", f) | Top |
|
Posted by
| Halig
Portugal (123 posts) Bio
|
Date
| Reply #10 on Thu 12 Mar 2015 07:22 AM (UTC) |
Message
| Hi. I've manage to get that working, with the help on the forum. I was doing something wrong. | 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.
27,795 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top