I'm doing something wrong obviously but I'm not sure what. I tried both patterns but I get the same error.
Could someone explain this to me?
Patterns:
You bleed (\d+) health.
You bleed (\w+) health.
Script:
clotamt=((matches[2]/20)-2)
if clotting == 1 then
if matches[2] > 80 then
send("clot " ..clotamt)
end
end
Error msg:
LUA error running script You bleed (\w+) health. (Trigger627) ERROR:Lua error:[string "function Trigger627()..."]:4: attempt to compare number with string
Comparing # to string error.
Re: Comparing # to string error.
The error simply says that you can't do mathematical calculations on a string e.g. the expression ("Tony"/20)-3 makes no sense.
The capture pattern (\d+) is fine, but the error is in the script. Matches[] is a string table. Lua has no way to know if your number capture (\d+) e.g. "345" has to be interpreted as a string "345" or the number 345. This is why you need to explicitely use the tonumber() conversion function if you want to use the content of matches[] as numbers.
clotamt=((tonumber(matches[2])/20)-2)
The capture pattern (\d+) is fine, but the error is in the script. Matches[] is a string table. Lua has no way to know if your number capture (\d+) e.g. "345" has to be interpreted as a string "345" or the number 345. This is why you need to explicitely use the tonumber() conversion function if you want to use the content of matches[] as numbers.
clotamt=((tonumber(matches[2])/20)-2)
Re: Comparing # to string error.
ed:You bleed 90 health.
Trigger name=You bleed (\d+) health.(You bleed (\d+) health.) matched.
capture group #0 = <You bleed 90 health.>
capture group #1 = <90>
LUA OK script You bleed (\d+) health. (Trigger627) ran without errors
new line arrived:Health Lost: 90
says the trigger is matching and that the script is running without errors, but it's not doing what it's supposed to.
clotamt=((tonumber(matches[2])/20)-2)
if clotting == 1 then
if tonumber(matches[2]) > 80 then
send("clot " ..clotamt)
end
end
Trigger name=You bleed (\d+) health.(You bleed (\d+) health.) matched.
capture group #0 = <You bleed 90 health.>
capture group #1 = <90>
LUA OK script You bleed (\d+) health. (Trigger627) ran without errors
new line arrived:Health Lost: 90
says the trigger is matching and that the script is running without errors, but it's not doing what it's supposed to.
clotamt=((tonumber(matches[2])/20)-2)
if clotting == 1 then
if tonumber(matches[2]) > 80 then
send("clot " ..clotamt)
end
end
Re: Comparing # to string error.
Sorry, not sure what the problem with your script is (perhaps just a math error?), but this is how I'm doing it. Maybe this will help.
Code: Select all
Trig Pattern: ^You bleed (\d+) health\.$
Script:
if (tonumber(matches[2]) > 29) then doclot(tonumber(matches[2])/40) end
function doclot(num)
fg("red")
bg("black")
echo("<--- Gonna Clot")
if num < 0 then num = 0 end
while num > 0 do
sendr("clot")
num = num - 1
end
end
Re: Comparing # to string error.
Most likely your global variable clotting is not equal to 1. To debug your script you need to print the values of the respective variables to see where the error is. Here you go:Xixity wrote:ed:You bleed 90 health.
Trigger name=You bleed (\d+) health.(You bleed (\d+) health.) matched.
capture group #0 = <You bleed 90 health.>
capture group #1 = <90>
LUA OK script You bleed (\d+) health. (Trigger627) ran without errors
new line arrived:Health Lost: 90
says the trigger is matching and that the script is running without errors, but it's not doing what it's supposed to.
clotamt=((tonumber(matches[2])/20)-2)
if clotting == 1 then
if tonumber(matches[2]) > 80 then
send("clot " ..clotamt)
end
end
Code: Select all
-- declare a number variable c to hold the number caught in capture group #1
local c = tonumber( matches[2] )
-- declare a second number to hold the value of your calculation and print the result
local clot = c / 20 - 2
echo( "c=" .. c .. " clot=" .. clot .. " clotting=" .. clotting .. "\n" )
if clotting == 1 then
if clot > 80 then
send( "clot " .. clot )
end
end