So, being new to Corona and all, I’ve decided to learn Corona by means of creating a game, but I stumbled upon a weird problem when it comes to the director class and the removeSelf() function.
A bit of background: The game should go that there’s a continuous spawning of an object, and when it collides with something it removes itself. So I’ve set it up. It works perfectly fine. Problem is, whenever I use the director class and switch scenes, whenever I come back to the game scene, the collision is having some errors. It appears as if it’s detecting each of the new objects as two objects, so it tries to removeSelf() twice (or it detects that it collided twice, that same object). Of course, the second attempt fails, thus causing the error I see below:
leftWall&objectcollided
removing object
done removing object
leftWall&objectcollided
removing object
Runtime error
\*\*\*.lua:148: attempt to call method 'removeSelf' (a nil value)
stack traceback:
[C]: in function 'removeSelf'
\*\*\*:148: in function
?: in function <?:214>
I think that’s how it’s going though. >.<. i still need to get used understanding these error messages but hope some of you will be able help me. :="">
If it helps, my code looks something like this:
[lua]print(e.object1.name … “&” … e.object2.name … “collided”)
if(e.object1.name == “leftWall”) then
print("removing " … e.object2.name)
e.object2:removeSelf(); print(“done removing object”);
end[/lua]
This only happens if I switch scenes using the director class (and by that, I mean I’ve loaded this scene at least once, then I move to a different scene then come back to this [the game’s] scene). I have a code that resets the game without switching scenes and it works fine.
[import]uid: 45459 topic_id: 8033 reply_id: 308033[/import] </.>