I have a trigger with the following Lua:
abi=matches[2]
bdee=matches[3]
echo(abi)
echo(bdee)
if abi<bdee then echo("yay") end
I could see the echos so i know my captures were correct (both are numbers), but when i try to do the a<b, it says in the debug about trying to compare a number with a string.
How do I make it know that bdee is not a string but the number that i captured?
Comparing 2 variables became variable and string
Re: Comparing 2 variables became variable and string
i've tried that actually, it's the line
if abi<bdee then echo("yay") end
that doesn't work. Even if I had tonumber the 2 variables it still tells me i am comparing a number to a string.
if abi<bdee then echo("yay") end
that doesn't work. Even if I had tonumber the 2 variables it still tells me i am comparing a number to a string.
- SlySven
- Posts: 1019
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: Comparing 2 variables became variable and string
Perhaps lua is helpfully transforming the variables just at the wrong time - how about the more explicit:It might be that the action of echo ing the variables is turning one of them back to a string internally - especially if the variable has a space (decimal point a.k.a. a full stop) or something else that might appear near a number without actually making it NOT a number?
Code: Select all
abi=matches[2]
bdee=matches[3]
echo(abi)
echo(bdee)
if tonumber(abi) < tonumber(bdee) then echo("yay") end
Re: Comparing 2 variables became variable and string
I didn't have that echo() with the if then function at the same time, i tested the captures first using the echo, and i replaced the echo functions with the if then function.SlySven wrote:Perhaps lua is helpfully transforming the variables just at the wrong time - how about the more explicit:It might be that the action of echo ing the variables is turning one of them back to a string internally - especially if the variable has a space (decimal point a.k.a. a full stop) or something else that might appear near a number without actually making it NOT a number?Code: Select all
abi=matches[2] bdee=matches[3] echo(abi) echo(bdee) if tonumber(abi) < tonumber(bdee) then echo("yay") end
And i also did that tonumber(abi) < tonumber(bdee) as well
Re: Comparing 2 variables became variable and string
I am sorry. It works now.
I just cut and pasted the same code and it works now.
No idea why.
edited: the same code is the one with the tonumber()<tonumber() to clarify. I must have left something somewhere that got cut away. Hopefully.
Thank you all for the help.
I just cut and pasted the same code and it works now.
No idea why.
edited: the same code is the one with the tonumber()<tonumber() to clarify. I must have left something somewhere that got cut away. Hopefully.
Thank you all for the help.