[Solved] Changing a scene using JavaScript

Hello,

Does anyone know what the script would be to change to a specific scene using JavaScript?

Many thanks.

https://docs.gdevelop-app.com/GDJS%20Runtime%20Documentation/gdjs.RuntimeScene.html#requestChange

1 Like

runtimeScene.requestChange(X,Y);

1 Like

Adding some examples to the answer of Bouh :wink:

//Switching scenes
runtimeScene.requestChange(gdjs.RuntimeScene.REPLACE_SCENE, "sceneName");

//Pausing scene and starting another
runtimeScene.requestChange(gdjs.RuntimeScene.PUSH_SCENE, "sceneName");

//Restauring the paused scene
runtimeScene.requestChange(gdjs.RuntimeScene.POP_SCENE);

// Cancel any change request if it is not too late (do not do that, this is just an example but you really shouldn't do that)
runtimeScene.requestChange(gdjs.RuntimeScene.CONTINUE);
3 Likes

Thanks all :slight_smile:

Seems like this does not work anymore for GDevelop 5?

runtimeScene.requestChange(gdjs.RuntimeScene.REPLACE_SCENE, jump)
runtimeScene.requestChange(gdjs.RuntimeScene.CLEAR_SCENES, jump);

None of them work.

Indeed, the enum has been separated from RuntimeScene, it has now its own object:

// gdjs.RuntimeScene => gdjs.SceneChangeRequest
runtimeScene.requestChange(gdjs.SceneChangeRequest.PUSH_SCENE, "New scene");

Ok thanks mate. Its working now.