So I’m making a word game similar to Plinko from the Price Is Right.
Having some trouble with this function that determines when a chip
lands in a slot at the bottom of the board (and which slot it has
occupied). The error I’m getting says ‘event’ is nil on this line:
if(event.phase == “ended” and colObj == slot[i])then
any ideas? Here’s the rest of the code:
function chipLanded(event)
--boolean to indicate chip has landed
local landed = false
local emptySlots = {1,2,3,4,5}
--storage for slot physics objects
local slot1 = display.newRect(75,148,32,17)
slot1.alpha = 0
slot1:addEventListener(“collision”,slot1)
local slot2 = display.newRect(117,457,32,17)
slot2.alpha = 0
slot2:addEventListener(“collision”,slot2)
local slot3 = display.newRect(156,460,26,17)
slot3.alpha = 0
slot3:addEventListener(“collision”,slot3)
local slot4 = display.newRect(195,460,23,17)
slot4.alpha = 0
slot4:addEventListener(“collision”,slot4)
local slot5 = display.newRect(231,457,28,19)
slot5.alpha = 0
slot5:addEventListener(“collision”,slot5)
--object chip is colliding with
local colObj = event.object2.name
if(event.phase == “ended” and colObj == slot[i])then
--make physics bodies
for i=1,5 do
physics.addBody(slot[i],physicsData:get(slot[i]))
--see which body was involved in the collision
if(colObj == slot[i])then
print (colObj) – debug only
landed = true
table.remove(emptySlots[i]) – take occupied slot out
of table for this itteration
end
end
end
for i,v in pairs(emptySlots) do print(i,v) end --debug only
return true, emptySlots,landed
end