recently I've been attempting to achieve some sort of collision between the player and a box, using BoundingBox.lua. but, i keep getting this error when starting the game:
Error
Syntax error: BoundingBox.lua:7: ')' expected near '.'
here's the code:
function CheckCollision(player.x, player.y, player.w, player.h, box.x, box.y, box.w, box.h)
if player.x > box.x + box.w - 1 or -- Is player. on the right side of box.?
player.y > box.y + box.h - 1 or -- Is player. under box.?
box.x > player.x + player.w - 1 or -- Is box. on the right side of player.?
box.y > player.y + player.h - 1 -- Is b2 under b1?
then
return false -- No collision. Yay!
else
return true -- Yes collision. Ouch!
end
end
as i understand it, i'm supposed to put a ')' somewhere, but i do not understand where it is supposed to be.
thanks in advance
BoundingBox.lua:7: ')' expected near '.'
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: BoundingBox.lua:7: ')' expected near '.'
You have player.x player.y player.w... those are not valid arguments
You either do:
or:
You either do:
Code: Select all
function CheckCollision(x, y, w, h, bx, by, bw, bh)
local player = {x = x, y = y, w = w, h = h}
local box = {x = bx, y = by, w = bw, h = bh}
-- Your code
end
Code: Select all
function CheckCollision(player, box)
-- Your code
end
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: BoundingBox.lua:7: ')' expected near '.'
Here's a working collision check as long as both boxes have valid X, Y, W and H passed.
Returns true if overlapping and false if not all in one line. (Well three)
An alternative version where you pass the two boxes themselves instead:
This way it's not specific to the player and box but can be used for any two box objects.
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
An alternative version where you pass the two boxes themselves instead:
Code: Select all
function CheckCollision(b1, b2)
return b1.x < b2.x+b2.w and b2.x < b1.x+b1.w and b1.y < b2.y+b2.h and b2.y < b1.y+b1.h
end
Who is online
Users browsing this forum: Bing [Bot] and 5 guests