[Solved] List the whole scene list

Hello,

Does somebody knows how to easily list all the scenes of the game (and display or store it in a structure var) ?

I’m trying to create a tool to allow easy and fast access to every scenes of the project. There is no dedicated expression to retrieve the list, and i can’t find what i’m looking for in GDJS :frowning:.

Help appreciated :slight_smile:

You can loop on layouts for get each name.

var scene = runtimeScene;
var game = scene.getGame();
//Create a loop and use the index instead 0 in next line:
game.getGameData().layouts[0].name  //This name is the name in project manager :)

There are no expressions for this because GD didn’t return list of string.

I think the way to do this in GD is open first scene, get and save the name of scene with CurrentSceneName() in a global variable, and start next scene with the action (you need set the name manually).
And you chain all scenes.
But load all scenes with like this way can be a pain for old pc haha don’t do that.

1 Like

Yes Bouh, but as you may think, i’ve seen this idea, but it’s not a solution :stuck_out_tongue: i’d better create manually an index of all scenes…

No way to get the whole scenes list in a javascript event, just like the IDE does for some fields (like the action “change scene” for example) ?

The best could be a feature request for an expression like CurrentSceneName(), that could be something like “GetScenesList()” ? A basic use case could be a dynamic level selector in games.

A problem with that would be the lack of arrays in GDevelop. Sure it is possible to create a structure but it isn’t optimal. And I am not sure that this would actually be useful. In your example, a level selector, the programmer should know the scenes he created. A such implementation would only be useful if you plan to add a system to add scenes as dlc, Wich isn’t an easy task, and IMHO, if you manage to do that you can parse the game data to get all scenes through JavaScript.

The lack of array is something, it’s why i ask about a structure variable (or even a minimal result like a json string to parse).

In my case it would be very useful. A use case for everyone could be a level selector, but in my precise use case it’s part of an internal debugger.

I work with 2 non developer mates (graphist and writer), and actually they can navigate through scenes with a debugger command console (ingame, because there are not using Gdevelop). But they have to know the name of the scene before go to it with a command, and they have to refer to an external document to find the reference of the scene they want to access… A bit boring…

As there is an expression to get the CurrentSceneName(), a way to retrieve the scene list with same simplicity would be optimal :slight_smile: Unfortunately, my javascript skills aren’t good enough :frowning:

:thinking: actually your right this is indeed a good idea. I can see if I can try to implement that later and make a PR.

1 Like

Ok my PC is broken and I forgot to do it while I could use the PC of a friend so in the meantime here is some Js code that Should(the should means I didn’t test it) do the trick. Wrap it in an extension Function or something.

let variable = runtimeScene.getVariables().get("sceneList");
let scenesData = runtimeScene.getGame().getGameData().layouts

for (let i in scenesData) {
    variable.getChild(i).setString(scenesData[i].name)
}

This will make a structure variable named sceneList containing number indexes (0, 1, 2 etc) with a scene name in each one.

I came up myself with that but noticed after writing Bouh did pretty much write this (but without variables and for loop) so sorry if it seems I’m copying Bouh came up with this the first.

1 Like

Thanks @arthuro555, it’s works perfectly for what i need.

I keep thinking there should be an expression in Gdevelop for that, or any other way to allow a no-code usage.

1 Like

Yes, and I agree with you. This is only a temporary thing because my PC is broken. Writing Js is feasible on mobile but not contributing to GDevelop. When I can access a friend’s PC I will make a PR for that.