Bizarre Trigger Error

Post Reply
Katerine459
Posts: 4
Joined: Mon Nov 26, 2018 9:59 pm

Bizarre Trigger Error

Post by Katerine459 » Tue Nov 27, 2018 8:32 pm

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!

Corim
Posts: 1
Joined: Sat Dec 01, 2018 1:16 am

Re: Bizarre Trigger Error

Post by Corim » Sat Dec 01, 2018 1:21 am

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.

Katerine459
Posts: 4
Joined: Mon Nov 26, 2018 9:59 pm

Re: Bizarre Trigger Error

Post by Katerine459 » Sat Dec 01, 2018 3:25 am

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])

User avatar
Vadi
Posts: 4610
Joined: Sat Mar 14, 2009 3:13 pm

Re: Bizarre Trigger Error

Post by Vadi » Tue Dec 04, 2018 7:24 pm

Yep, that would be it!

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests