[solved] Global variables not displaying on text object

Greetings, I’d like to report what I think might be a bug.

I made some global variables for stats, and I’d like for them to display on a text object:

However, when I run the game:

Both values display as 0 for some reason.
Here’s the global variables:

Basically, they both worked just a moment ago, but I changed the name of the variable to fix a capitalization error, and now it doesn’t work (Yes, I changed the text objects to reflect the change). Now it just displays as 0. For some reason though, whenever I retype the OLD name into the text object (Even though the global variable is now a different name), it suddenly works again.

I’m entirely convinced that this is a bug. Or am I just missing something important?
I debugged, I searched parameters, and I reinstalled. Nothing fixed it.

Can someone please help me?

Any chance you can send me the link to the project by DM so I can debug this?

Don’t check in the variables editor, check in the debugger in real-time, you probably have other events breaking your variable structure, hence returning 0 instead of the expected value, and hence fixing it by changing the name.

1 Like

Alright, here’s the file. Thanks for taking the time to check it out.

Upon relaunching, I noticed there was a new update. Maybe there’s something that might’ve broke?

And yea, I remembered to check the debugger myself too. Despite the values reading what they should read, they all come back as 0 in the text object. I also used parameter search in the events to make sure I didn’t miss changing anything when I renamed.

Hey. I looked at your project. I couldn’t get the player to move but then noticed the playerStat in gameManager had a capital P. I changed to lower case and the player moved.

This is the line that I changed:

When I manually changed the values in the debugger, everything was saved and loaded. I don’t see any actions to change the values. I think what’s happening is that no matter what you set the variables to in the Global Variable screen is overwritten when you load the variable from storage. I don’t see any actions in between the load and save that change the values. So, it just saves and loads the same values.

I’m wondering if when you changed the names, the new names were being ignored because they didn’t exist in the save data when you reload the variables/structures.

Did you try deleting the saved data through your “del” key events? Without anything to load, it seems to grab the default value from the Global variable setting screen and works for me.

How strange, I already tried using the delete function to try this, and nothing happened.

However, when I mashed the delete key in game a few times, and restarted again, the values were back.

I must’ve gotten confused when editing, but the values are back now. Guess I know the save and load works properly, huh?

Also, yeah, I remembered to fix the capitalization error

1 Like

I think what was happening is after you deleted the settings, the game saved the values back again before exiting. When the game is reloaded , the saved values override the default value. I’m wondering if after you delete the storage you might need to reintialize some variables to a defalt value before it saves the variables again.

In Gdevelop, just trying to read a variable to display it in a text object will create the variable and set it to a default value. Zero if the variable is used for numbers.

Another option is to separate the variables between gameplay and game settings. Save, load and delete them separately. So, you can just reset the gameplay settings.

It happened to me very recently, so I figured something similar was going on here. :wink:
All good, then. :+1: