if you have written your code like that, then objectTag will point to the last raft, so only the last object is going to have the eventListener added to it
you could reorder it like this
local mRandom = math.random
local raft = {"Raft1" ,"Raft2","Raft3"}
local objectTag = 0
local object = {}
--MOVE THIS FUNCTION SO WE CAN CALL ON IT LATER
--while the frog is on the log...
function raftCollide(event)
if ( event.phase == "began" ) then
isOnRaft = isOnRaft + 1
elseif ( event.phase == "ended" )then
isOnRaft = isOnRaft - 1
end
end
function spawnlogright()
objectTag = objectTag + 1
local objIdx = mRandom(#raft)
local objName = raft[objIdx]
object[objectTag] = display.newImage(objName..".png")
object[objectTag].x = 416
object[objectTag].y = 72
object[objectTag].name = objectTag
transition.to(object[objectTag], {time = 10000, x = -96, onComplete = function(obj) obj:removeSelf(); obj = nil; end})
physics.addBody( object[objectTag], "static", {isSensor = true})
--ADD EVENT LISTENER TO EACH LOG
--add event for 'walking on the log'
object[objectTag]:addEventListener("collision",raftCollide)
end
spawnlogright()
timer.performWithDelay(3000,spawnlogright,0)
--AND SO ON WITH MORE LOGS....
does the timer function spawn the logs? you may need to add an event argument to the spawn functions. Also, try and put all the spawns in one function, that'll give you more control over the index you're inserting the rafts into