Page 1 of 1

HEELP!

Posted: Thu Mar 26, 2015 5:01 pm
by Porkinator
Help! I'm trying to make a humble little game and lua is acting strange!
I have not one but TWO problems! Firstly, in my CheckCollision function, it keeps telling me that I am comparing a number with nil.
What?? I see nothing with a nil value here.

Code: Select all

function CheckCollision(x1, y1, w1, h1, x2, y2, w2, h2)
return 
    x1 x2+w2 and
	x2 < x1+w1 and
	y1 < y2+h2 and
	y2 < y1+h1
end
Also, it then tells me that I need to end my CheckCollision.

Code: Select all

function CheckCollision(x1,y1,w1,h1,x2,y2,w2,h2)
	return x1 < x2+w2 and
	x2 < x1+w1 and
	y1 < y2+h2 and
	y2 < y1+h1
end
Here you can see that in my other piece of code, the only difference is in spacing. There is still one end in both of them.
So what is going on? Is it something else in my code, or what?

Re: HEELP!

Posted: Thu Mar 26, 2015 5:18 pm
by arampl
This is illegal: "x1 x2+w2"

Re: HEELP!

Posted: Thu Mar 26, 2015 5:24 pm
by Robin
  1. Please use a more descriptive topic. "HEELP!" doesn't help anyone, especially not other people who are looking at the forum and might have the same problem as you. You can still change the topic name by editing your original post.
  2. Please upload a .love. If you can't find the source of the problem yourself, it's often because the problem's somewhere else, so if you supply a .love, we have what you have and can fix your problem much more easily. If you don't want to share your whole game, you can make a copy and remove all elements that you don't want to share, then check the resulting project if it has the same bug, and upload that.
  3. You can't insert a newline everywhere and expect it to work. Try this:

    Code: Select all

        function CheckCollision(x1,y1,w1,h1,x2,y2,w2,h2)
           return (x1 < x2+w2 and
           x2 < x1+w1 and
           y1 < y2+h2 and
           y2 < y1+h1)
        end
    Parentheses allow for newlines to be used inside.

Re: HEELP!

Posted: Fri Mar 27, 2015 1:23 pm
by Porkinator
Ok, but it's still giving me the comparing number with nil error. Any thoughts on that?

Re: HEELP!

Posted: Fri Mar 27, 2015 1:39 pm
by zorg
You're probably not passing the function enough parameters, or one (or more) of them is nil. See where you call the function from, maybe the problem lies there.

Re: HEELP!

Posted: Fri Mar 27, 2015 3:46 pm
by Robin
Again, upload the .love, that'll help us help you.