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 text is on 2 or more lines
Trigger text is on 2 or more lines
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #15 on Sun 18 Sep 2011 07:59 AM (UTC) |
Message
|
Blixel said:
P.S. I don't know how to preview my posts either.
You can't. Sadly the forum doesn't let you do that. :(
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #16 on Sun 18 Sep 2011 08:04 AM (UTC) |
Message
|
Blixel said:
It is often the case that when drinking a flask (or doing other things) the game will output one or the other of the following:
You don't have one!
>You don't have one!
The only difference is that leading ">"
Ada said:
The following regular expression should work:
^(\>)?You don\'t have one\!$
You don't need to make it a capture. So this also will work:
^\>?You don\'t have one\!$
Or even remove the requirement that it is at the start of the line (a little more dangerous):
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #17 on Sun 18 Sep 2011 08:06 AM (UTC) |
Message
|
Quote:
That makes it look for this text:
^(\>)?You have (.*?)\/(.*?) hitpoints(.*?)$
Is this a plugin? In which case the symbols < > and & need to become < > & |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Blixel
(80 posts) Bio
|
Date
| Reply #18 on Sun 18 Sep 2011 08:41 AM (UTC) |
Message
| Oh boy ... some issue or another always pops up. (I'll address the regular expression thing next, but first - I want to revisit the flask thing for a moment.)
But no worries... I actually came up with a solution on my own! I think it's a good one, but I want to run it by you.
It is sometimes the case that you will only have 1 line worth of inventory. (This is more of an issue when looking at items on the ground. Usually your inventory will span at least 2 lines, but often, the "inventory" on the ground fits on one line.)
Anyway... I found that the logic "we" (you) came up with was missing one small piece of the puzzle.
Take the following line of inventory as an example.
You are carrying a shortsword, some clothmail and 0 gold pieces.
That all fits on one line with a little room to spare.
When I run the countflasks command ... the first time I run it, it gives me this:
>inventory
You are carrying a shortsword, some clothmail and 0 gold pieces.
The second time I run it, it gives me this:
>inventory
You are carrying a shortsword, some clothmail and 0 gold pieces.
No. of flasks : 0
The problem seems to be that the trigger system assumed there would always be at least 2 lines. So here's what I did to work around it.
My main alias is called "countflasks" and it does this:
EnableTrigger("InvStart", true)
Send ("inventory")
That will trigger the "You are carrying" trigger which now does this:
myinv = "%0"
if string.sub(myinv, string.len(myinv) - 6, string.len(myinv)) == "pieces." then
EnableTrigger("InvStart", false)
Execute ("FlaskCount")
else
EnableTrigger("InvFull", true)
end
In other words, if "pieces." is the end of that first line, then we are done. We shut off the InvStart trigger and Execute FlaskCount. If "pieces." does not end the line, then we turn on InvFull which now does this:
myinv = myinv .. "%0"
if string.sub(myinv, string.len(myinv) - 6, string.len(myinv)) == "piece." then
EnableTrigger("InvStart", false)
EnableTrigger("InvFull", false)
Execute ("FlaskCount")
end
This trigger effectively runs in a continuous loop until some line ends with "pieces."
When that finally happens, it shuts off both triggers and then Executes FlaskCount which does the actual counting:
flaskcount = 0
for word in string.gmatch(myinv, "flask") do
flaskcount = flaskcount + 1
end
Note("No. of flasks : " .. flaskcount)
It seems to work. But if you have ideas for an improvement, I'm open to it.
In particular because I copied this logic verbatim when counting corpses and "chests" in a room. And I'm wondering if this logic can be consolidated:
corpsecount = 0
chestcount = 0
for word in string.gmatch(roomitems, "corpse") do
corpsecount = corpsecount + 1
end
for word in string.gmatch(roomitems, "chest") do
chestcount = chestcount + 1
end
Note("No. of corpses : " .. corpsecount)
Note("No. of chests : " .. chestcount)
Not a big deal ... but I assume there is a way to add the corpsecount and chestcount without doing two separate for loops that loop over the same data.
| Top |
|
Posted by
| Blixel
(80 posts) Bio
|
Date
| Reply #19 on Sun 18 Sep 2011 09:35 AM (UTC) Amended on Sun 18 Sep 2011 09:44 AM (UTC) by Blixel
|
Message
|
Ada said: A trigger either matches or not matches. The compile error you're getting means it -is- matching in both cases but the associated script is not in working order. Can you paste the triggers and the text they're supposed to match here please?
To answer your second question first, 'health' or 'hea' is a game command.
>help health
The "health" command will let you see how many hit points you have left and
what your maximum hit point amount is. If you are of a magical class, it will
show your spell points and your spell point maximum. You will also be told how
many minutes you have left to eat food before you begin to starve to death.
And, if you are diseased, it will let you know that too. Type: health or hea.
The normal output for 'hea' looks like this:
You have 95/96 hitpoints and 38/38 spellpoints.
You are middle-aged.
You will need to eat within 11 minutes.
I use that first line as a trigger to do a simple math calculation so that I will automatically drink a flask (which restores full health) when my health drops below a certain point.
Whenever a mob hits me, it sets off a trigger that automatically does this: Send ("health")
For example ... >The imp hits you for 15 hps!
That automatically triggers Send ("health")
Then I have this trigger:
^You have (.*?)\/(.*?) hitpoints(.*?)$|^>You have (.*?)\/(.*?) hitpoints(.*?)$
As you can see, that is simply evaluating what comes from the "health" command (which again, is a game command.)
This is the point where it dies if I use this as the trigger instead:
^(\>)?You have (.*?)\/(.*?) hitpoints(.*?)$
And Nick's idea of using this as the trigger:
^\>?You have (.*?)\/(.*?) hitpoints(.*?)$
...solves it as well. So for some reason, it doesn't like those parenthesis. I don't understand regular expressions well enough to know why that's the case.
So ... for the curiously minded, moving on with the flow...
The code in that trigger is:
if (%1 < (%2 * .3)) then
EnableTrigger("FlaskEmergency", true)
Send ("drink flask")
elseif (%1 < (%2 * .5)) then
ColourNote ("black", "red", "Health is %1")
elseif (%1 < (%2 * .6)) then
ColourNote ("black", "orange", "Health is %1")
elseif (%1 < (%2 * .7)) then
ColourNote ("white", "green", "Health is %1")
else
ColourNote ("white", "blue", "Health is %1")
end
EDIT: I think I just figured it out. Something Nick said. He said "You don't need to make it a capture...."
So I think (and correct me if I'm wrong), but I think by having the trigger start with parenthesis, it's making my %1 and %2 variables screw up. In other words, %1 would need to become %2, and %2 would need to become %3. Is that right?
The code for the FlaskEmergency trigger is:
EnableTrigger("FlaskEmergency", false)
Execute ("countflasks")
EnableTrigger("FlaskEmergencyCount", true)
The countflasks alias does this:
EnableTrigger("InvStart", true)
Send ("inventory")
...that part is all worked out... You know what the InvStart/InvFull does because you wrote it.
So the FlaskEmergencyCount is looking for "pieces." as its trigger text.
And the whole point of this trigger is so our character can teleport to safety if he is out of flasks.
The code for the FlaskEmergencyCount is:
EnableTrigger("FlaskEmergencyCount", false)
if (flaskcount == 0) then
giveup = true
Send ("rub key")
EnableTrigger("TeleportSafetyCheck", true)
elseif (flaskcount == 1) then
ColourNote ("white", "red", "==========================")
ColourNote ("white", "red", "WARNING: 1 Flask Remaining")
ColourNote ("white", "red", "==========================")
end
Whew ... I think I covered everything.
The bottom line here is that one Regular Expression ... for reasons that I don't even begin to understand, one expression works, and the other completely bombs ... with compile errors. | Top |
|
Posted by
| Ada
(20 posts) Bio
|
Date
| Reply #20 on Sun 18 Sep 2011 11:07 AM (UTC) |
Message
| Yep, Nick is right. Simply not using the parentheses for the '>' character solves the problem because then it is no longer part of the capture group. So problem solved! :D | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #21 on Sun 18 Sep 2011 12:22 PM (UTC) |
Message
|
Quote:
So I think (and correct me if I'm wrong), but I think by having the trigger start with parenthesis, it's making my %1 and %2 variables screw up. In other words, %1 would need to become %2, and %2 would need to become %3. Is that right?
Exactly. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
61,952 views.
This is page 2, subject is 2 pages long:
1
2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top