help with script
-
- Posts: 10
- Joined: Sun Feb 14, 2016 1:06 pm
help with script
I need to write a very simple script that will beep when my hp is below a certain amount. What I'm stuck on is how to "read" the screen in my script, so when it says "HP: X", my script can take in that information.
-
- Posts: 27
- Joined: Fri Jun 26, 2015 8:52 am
Re: help with script
The trigger line will depend on the prompt.You'll want to brush up on your regular expressions if you haven't already. A simple example is that if your prompt reads thus: HP: 125 MP: 98 Then you'll make your trigger expression
The (\d+) part captures any number which you can get back with matches[2], the MP value is matches[3], if you had more items in parenthesis after that, the pattern continues. If you want to do something when your hp is below a certain value, say 50, you would use the script.
Though I'd recommend setting up a a variable, say 'hp_alarm = 50', and use 'matches[2] < hp_alarm'.
-
- Posts: 10
- Joined: Sun Feb 14, 2016 1:06 pm
Re: help with script
brilliant, thank you my friend.
-
- Posts: 10
- Joined: Sun Feb 14, 2016 1:06 pm
Re: help with script
So wait what does the ^ do? Does that prompt mudlet to read the line?
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: help with script
The '^' (and the '$' !) are meta-characters that mean in this case the start of the line (and the end of the line) respectively. If there is anything else before (or after) in the line then this rexexp will NOT match on that line so it will not be processed...!
-
- Posts: 27
- Joined: Fri Jun 26, 2015 8:52 am
Re: help with script
What SlySven said. Here's a list of metacharacters. And HERE is an tool that'll let you check if your regular expressions are right. Using the start of line and end of line characters isn't necessary, but is generally recommended, as it prevents your trigger from matching unintended things. Like, if someone sent you a message containing "blah blah HP: 123 blah," you want the trigger to not fire.
Re: help with script
Also, since matches[2] is a string, you'll have to convert it to a number with tonumber( matches[2]) before comparing.