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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Trigger to save to variable
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Trigger to save to variable

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


Posted by Halig   Portugal  (123 posts)  [Biography] 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>
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] 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.
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] 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.
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] 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.
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] 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)
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] 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.
[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.


5,569 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 FutureQuest]