Hello, I just started using this MUD-client, and I'm amazed by the possibilites it offers, and the SPEED!
However!
I'm getting really frustrated by how this client handles triggers and variables, I felt it was easier on zMud and mudmaster.
On mudmaster I have a script that always logs my current hps, mana etc from the prompt.
In the prompt there's also a function that shows the party memeber with the lowest hps.
I have a trigger that puts this name into a variable to be easily targetted to cast a heal spell on(I'm a healer) in
stressfull situations.
I tried to replicate this in Mudlet and after a fair bit of trying(and screaming,and cursing) I've finally
come to the conclusion others might be better at this than I...
My normal prompt looks like this:
<462/1169hp 1309/1424m 571/691mv 24e>[Nonexp]
and I've managed to store my current hps etc(in this case 462) as a call-able variable.
I used a regex trigger pattern, and got it to return with an echo:
<(\d+)/1169hp
health = matches[2]
echo(health .. " is my current hp")
but
when I'm teamed up and the prompt changes to this:
[Gimli 39%]<462/1169hp 1309/1424m 571/691mv 24e>[Nonexp]
I cannot seem to successfully grab the name Gimli and store it as a variable, for example Healtarget.
I suspect this has something to do with the square brackets used in the prompt [], and that these
interfers with the coding in Mudlet?
My best result so far is:
(.*)(\w+) (\d+)%]<(.*)/(.*)hp
healtarget = matches[2]
echo(healtarget .. " is the new healtarget")
and this returns: [Giml is the new healtarget
which is unusable for me...
Anyone have a suggestion to how I can fix this?
Any help will be appreciated!
Grabbing info from prompt to store as variables
Re: Grabbing info from prompt to store as variables
This not a Mudlet issue, but a Regex issue. In your pattern, you need to escape the brackets. They have special meaning in Regex patterns.
Like so:
I don't know what matches will be. Use display() to work it out. This was written in the browser, on my phone. No guarantee it'll work out of the box. Once you get the pattern worked out, the variables will fall into place. Also, tonumber() the matches that should be numbers.
Like so:
Code: Select all
^\(?:[(\w+) (\d+)%\])?<(\d+)/(\d+)hp (\d+)/(\d+)m (\d+)/(\d+)mv (\d+)e>\[(\w+)\]
Re: Grabbing info from prompt to store as variables
You forgot to escape the first square bracket.
Code: Select all
^\(?:\[(\w+) (\d+)%\])?<(\d+)/(\d+)hp (\d+)/(\d+)m (\d+)/(\d+)mv (\d+)e>\[(\w+)\]
Re: Grabbing info from prompt to store as variables
Oh, snap. Thanks. Typing that out on my cell was a pain. Heh. Thanks for catching that.
Re: Grabbing info from prompt to store as variables
Thanks a bunch for replying. The code offered did not work, so I started tinkering with it.
A few tries later I started removing stuff, and when I tried this:
^\[(\w+) (\d+)%\]<(\d+)/(\d+)hp (\d+)/(\d+)m (\d+)/(\d+)mv (\d+)e>\[(\w+)\]
it worked! Not sure why removing the (?: and )? worked, but that was the only part of the code I didn't understand so I thought let's begin with that
What does (?: and )? do anyways?
Thanks again for the quick and helpfull tips!
A few tries later I started removing stuff, and when I tried this:
^\[(\w+) (\d+)%\]<(\d+)/(\d+)hp (\d+)/(\d+)m (\d+)/(\d+)mv (\d+)e>\[(\w+)\]
it worked! Not sure why removing the (?: and )? worked, but that was the only part of the code I didn't understand so I thought let's begin with that
What does (?: and )? do anyways?
Thanks again for the quick and helpfull tips!
Re: Grabbing info from prompt to store as variables
Oh snap! Now I have another problem. I was so sure if I got that line to work I could adapt it further, but nooo.
If I bring a pet, and that takes damage, I get a different prompt:
[Howler(PET) 85%]<1089/1193hp 1424/1424m 682/691mv 55e>[Nonexp]
so I tried to modify it to:
^\[(\w+)..(PET) (\d+)%\]<(\d+)/(\d+)hp (\d+)/(\d+)m (\d+)/(\d+)mv (\d+)e>\[(\w+)\]
and
^\[(\w+)(PET) (\d+)%\]<(\d+)/(\d+)hp (\d+)/(\d+)m (\d+)/(\d+)mv (\d+)e>\[(\w+)\]
but none of those work, so I must be missing something vital again.. and ideas as to how include the (PET) part in the line correctly?
If I bring a pet, and that takes damage, I get a different prompt:
[Howler(PET) 85%]<1089/1193hp 1424/1424m 682/691mv 55e>[Nonexp]
so I tried to modify it to:
^\[(\w+)..(PET) (\d+)%\]<(\d+)/(\d+)hp (\d+)/(\d+)m (\d+)/(\d+)mv (\d+)e>\[(\w+)\]
and
^\[(\w+)(PET) (\d+)%\]<(\d+)/(\d+)hp (\d+)/(\d+)m (\d+)/(\d+)mv (\d+)e>\[(\w+)\]
but none of those work, so I must be missing something vital again.. and ideas as to how include the (PET) part in the line correctly?
Re: Grabbing info from prompt to store as variables
Again, it's about escaping special Regex characters. In this new case, you need to escape the ()'s. So, it will be \(PET\).
Also, ?: and ? are special characters. The ?: at the beginning of a capture group makes it a non-capture group. It's used to group things in parentheses without returning the results to matches. The ? after a matched character/group makes it optional. For instance, (?:\[(\w+) (\d+)%\])? means that group is optional, but you don't want to capture [hjk 23%]. In this case, you only want to capture "hjk" and '23'.
Also, ?: and ? are special characters. The ?: at the beginning of a capture group makes it a non-capture group. It's used to group things in parentheses without returning the results to matches. The ? after a matched character/group makes it optional. For instance, (?:\[(\w+) (\d+)%\])? means that group is optional, but you don't want to capture [hjk 23%]. In this case, you only want to capture "hjk" and '23'.
Re: Grabbing info from prompt to store as variables
Ah, ok, now I understand. I got it working now.
I made a quick alias that uses the variables from that line:
if healtargetpercent < "30" then
send ("c heal " .. healtarget)
elseif healtargetpercent >= "80" then
send ("c resto " .. healtarget)
else send ("c cure critic " .. healtarget)
end
(where restoration<cure critic<heal)
and it works wonderfully. MUCH better than on my previous client.
Thanks again for the help, it's very much appreciated!
I made a quick alias that uses the variables from that line:
if healtargetpercent < "30" then
send ("c heal " .. healtarget)
elseif healtargetpercent >= "80" then
send ("c resto " .. healtarget)
else send ("c cure critic " .. healtarget)
end
(where restoration<cure critic<heal)
and it works wonderfully. MUCH better than on my previous client.
Thanks again for the help, it's very much appreciated!