if-then statement in a Trigger doesn't do anything

Post Reply
Trynt
Posts: 1
Joined: Tue Apr 27, 2010 6:29 am

if-then statement in a Trigger doesn't do anything

Post by Trynt »

Mudlet does not indicate a bug with this Trigger, but it just does not seem to be doing anything.

The line that sets off the Trigger is:

Code: Select all

^H:(\d)\d% M:

--It's my character's health. It captures the first digit in a two-digit health reading. So if my health is H:67%, it will capture the 6. I've it set as the "perl regex" type, and that works totally fine.


Then, in the big script response-box below it, I have typed :

Code: Select all

if matches[2] < 9 and analepticbal == 0 then
	send("stick analeptic")
else echo("You're Good!")
end
-- When I send("stick analeptic") to the MUD, the MUD will send back the line that I have separately Triggered to set analepticbal to 1. Then a few seconds later, the MUD sends the line that I have separately Triggered to set analepticbal to 0. I checked, it's changing the value just fine.

-- Mudlet seems to be fine with the Trigger as it does not give me any errors about it. The trigger just... does not seem to actually do anything when I'm watching my MUD in action.

(Help!)

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: if-then statement in a Trigger doesn't do anything

Post by tsuujin »

matches[2] is a string, and you're trying to compare it to a number.

you want
Code: [show] | [select all] lua
if tonumber(matches[2]) < 9 and analepticbal == 0 then
   send("stick analeptic")
else echo("You're Good!")
end

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: if-then statement in a Trigger doesn't do anything

Post by tsuujin »

I'm sure you also want your regex to be:
Code: [show] | [select all] lua
^H:(\d+)/\d+% M:
because it's probably not even matching right now.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: if-then statement in a Trigger doesn't do anything

Post by demonnic »

tsuujin wrote:I'm sure you also want your regex to be:
Code: [show] | [select all] lua
^H:(\d+)/\d+% M:
because it's probably not even matching right now.

no, his regex is good. the incoming text is a percent. The only time I think it wouldn't match, if if it's <10% or 100%.

Post Reply