Oncollision change scene problems.

I have been looking everywhere for a solution but I can’t find it but basically my problem is when I make two object collide they successfully collide but I can’t make them change to a different scene; I get this error.

<stack traceback:

[C]: in function ‘error’

?: in function ‘gotoScene’

level1.lua:23: in function <level1.lua:21>

?: in function <?:169>

 

It also says error loading module “game over” from file “game over.lua” which is the file I am trying to reach.

 

 

I apologise again for so many questions but I can’t find the answer to this.

I had the same problem today and this video helped me. I used a global collision and it works just fine.

https://www.youtube.com/watch?v=H06Zhvm5LGg

As well if it helps you look at my code :
 

local function onCollision(event)

if event.phase == “began” then

if event.object1.name == “playerumeu” then 

composer.gotoScene( “over”, “fade”, 500 )

end

end

end

Runtime: addEventListener(“collision”,onCollision)

Guys.  Don’t forget I’ve got a TON of examples here:

https://github.com/roaminggamer/CoronaGeek

and here:

https://github.com/roaminggamer/RG_FreeStuff

I have an example that almost perfectly matches what you’re doing. 

  1. Download this: https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

  2. Look at example:  10_change_scene_on_collision

I checked your example out before but it confused me as I didn’t know how to implement the code into my game so I just left it and improvised something else. But thanks anyway.

If you’re trying to change scenes and getting an error about the scene you’re going to, it’s very likely the error is in the scene you’re going to. I find it really helpful to test scenes by making them the main scene. In other words if I’m building a scene: gameover.lua in main.lua I can do:

composer.gotoScene(“gameover”)

by passing everything else and make sure that scene works before I try to have another scene go to it.

Rob

I had the same problem today and this video helped me. I used a global collision and it works just fine.

https://www.youtube.com/watch?v=H06Zhvm5LGg

As well if it helps you look at my code :
 

local function onCollision(event)

if event.phase == “began” then

if event.object1.name == “playerumeu” then 

composer.gotoScene( “over”, “fade”, 500 )

end

end

end

Runtime: addEventListener(“collision”,onCollision)

Guys.  Don’t forget I’ve got a TON of examples here:

https://github.com/roaminggamer/CoronaGeek

and here:

https://github.com/roaminggamer/RG_FreeStuff

I have an example that almost perfectly matches what you’re doing. 

  1. Download this: https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/composer_scene_manager.zip

  2. Look at example:  10_change_scene_on_collision

I checked your example out before but it confused me as I didn’t know how to implement the code into my game so I just left it and improvised something else. But thanks anyway.

If you’re trying to change scenes and getting an error about the scene you’re going to, it’s very likely the error is in the scene you’re going to. I find it really helpful to test scenes by making them the main scene. In other words if I’m building a scene: gameover.lua in main.lua I can do:

composer.gotoScene(“gameover”)

by passing everything else and make sure that scene works before I try to have another scene go to it.

Rob