Page 1 of 1

Bizarre Trigger Error

Posted: Tue Nov 27, 2018 8:32 pm
by Katerine459
Hi,
I've got a rather bizarre trigger problem (running 2.1), that I was hoping for some help with. Here's the Perl regex trigger:

Code: Select all

< (\w*) \| (\d*)\/(\d*)h (\d*)\/(\d*)m (\d*)\/(\d*)s \| O:(.*)
It does work. Here's the trigger code:

Code: Select all

local CurrHP = matches[3]
local MaxHP = matches[4]
local CurrMana = matches[5]
local MaxForHeal = MaxHP - MaxManaHeal - 5

echo (CurrHP  .. " " .. MaxForHeal .. " " .. CurrMana .. " " .. HealInProgress)
if (CurrHP < MaxForHeal) and (HealInProgress == 0) and (CurrMana > 12) then
	HealInProgress = 1
	send("heal")
end
(MaxManaHeal and HealInProgress are global variables set in a separate script).

When the trigger fires, I do get the echo statement. However, the If statement apparently never evaluates as true, even when the echo statement returns: 116 119 93 0.

I've tried just about every permutation, and have confirmed that even if the If statement just reads:

Code: Select all

if (CurrHP < MaxForHeal) then
...it still doesn't fire when CurrHP is less than MaxForHeal.

Many thanks for any help!

Re: Bizarre Trigger Error

Posted: Sat Dec 01, 2018 1:21 am
by Corim
I believe you still need to use tonumber(matches[3]) etc even if you capture the value using a \d in the pattern, otherwise they're still string variables.

Re: Bizarre Trigger Error

Posted: Sat Dec 01, 2018 3:25 am
by Katerine459
Never mind - I figured it out shortly after I posted (but it was a little while before the post was approved). The issue was that the grabbed values weren't automatically being converted to numbers. Fixed it by replacing the declarations with:

Code: Select all

local CurrHP = tonumber(matches[3])
local MaxHP = tonumber(matches[4])
local CurrMana = tonumber(matches[5])

Re: Bizarre Trigger Error

Posted: Tue Dec 04, 2018 7:24 pm
by Vadi
Yep, that would be it!