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.
Comparing Variables to a Number
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- RoosterDev
- Prole
- Posts: 2
- Joined: Thu Jun 28, 2012 12:57 am
Comparing Variables to a Number
- Attachments
-
- RedBoxGame.love
- (2.56 KiB) Downloaded 64 times
Re: Comparing Variables to a Number
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
Those 2 solutions should fix both of your problems. You only need to try one of them.
Code: Select all
if tonumber(boxX) < 0 then
- RoosterDev
- Prole
- Posts: 2
- Joined: Thu Jun 28, 2012 12:57 am
Re: Comparing Variables to a Number
Thanks! I do tend to accidentally make a regular value into a string, for some reason.
Who is online
Users browsing this forum: Google [Bot] and 6 guests