Page 1 of 1

Comparing Variables to a Number

Posted: Thu Jun 28, 2012 1:22 am
by RoosterDev
I tried to compare a variable to a number for a simple collision system, but it didn't work out. I got an error message the next time I tested my game on LÖVE saying, "attempt to compare string with number". I tried everything to solve this, but nothing worked. I even tried to put the function after the code registers the variables. So I decided to come to you guys.

Is there any way this can be solved?

I also uploaded the .love if that's any help. The forum rules said to do so.

Re: Comparing Variables to a Number

Posted: Thu Jun 28, 2012 3:50 am
by Qcode
Why do you have your variables as strings? In stead of having boxX as "0" have it as simply 0. Same with boxY. Another solution if you wanted to keep your variables as strings (not sure why you would want to do that) is to put at line 26

Code: Select all

if tonumber(boxX) < 0 then 
Those 2 solutions should fix both of your problems. You only need to try one of them.

Re: Comparing Variables to a Number

Posted: Thu Jun 28, 2012 4:27 am
by RoosterDev
Thanks! I do tend to accidentally make a regular value into a string, for some reason.