HEELP!

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Porkinator
Prole
Posts: 8
Joined: Wed Mar 25, 2015 12:58 pm

HEELP!

Post 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?
Why so serious, batman? :crazy:
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: HEELP!

Post by arampl »

This is illegal: "x1 x2+w2"
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: HEELP!

Post 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.
Help us help you: attach a .love.
User avatar
Porkinator
Prole
Posts: 8
Joined: Wed Mar 25, 2015 12:58 pm

Re: HEELP!

Post by Porkinator »

Ok, but it's still giving me the comparing number with nil error. Any thoughts on that?
Why so serious, batman? :crazy:
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: HEELP!

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: HEELP!

Post by Robin »

Again, upload the .love, that'll help us help you.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 240 guests