How to turn a scene variable into a global variable?

Hi everyone, My game has many scene variables, and now I need to turn one of them into a global variable. Is there a way to make a specific scene variable global without breaking the code?

Define a global variable with the same name and type as the scene variable. Delete the scene variable definition.

1 Like

Unfortunately, this doesn’t work. The game doesn’t recognize the global variable.
I have to manually specify in the code that the variable has become global.

Do you have any other ideas?

What version of GDevelop are you using? The steps I wrote worked for me in the latest version of GDevelop.

1 Like

I figured out the issue. Scene variables are being converted into global variables in the editor if they were set using the new method, where a scene or global variable is selected automatically. Since I started developing the game quite a while ago, it contains actions from an older version that cannot be changed automatically—or at least, I don’t know how to do it.

Do you have any ideas on how to solve this problem? :sweat_smile:

The quick but potentially damaging way I can think of with the older versions of GDevelop is to modify the game .json file. Make a backup of your game first, as that’s prone to mistakes.

A safer alternative is to create the global variable and then using the event editor search, manually replace each occurrence of the scene var with the global variable.

If that’s too much, another simple option is to keep the scene variable and create the global variable. At the start of the scene set the scene variable to the global variable, and as the very last event of the event sheet set the global variable to the scene variable.

1 Like

Thank you for the recommendations. This isn’t the first time you’ve helped me. :blush:

I managed to solve it using saving and loading variables across different scenes.