Comparing Variables to a Number

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
RoosterDev
Prole
Posts: 2
Joined: Thu Jun 28, 2012 12:57 am

Comparing Variables to a Number

Post 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.
Attachments
RedBoxGame.love
(2.56 KiB) Downloaded 64 times
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: Comparing Variables to a Number

Post 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.
User avatar
RoosterDev
Prole
Posts: 2
Joined: Thu Jun 28, 2012 12:57 am

Re: Comparing Variables to a Number

Post by RoosterDev »

Thanks! I do tend to accidentally make a regular value into a string, for some reason.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests