What's stopping me from turning every other variable into a global variable? (Besides object variables, of course...)

I’m very sorry if this is more fit for the “How do I…?” topic, I just believed it was more fit for GDevelop general.
In my games, I typically only use one scene, because I just prefer it that way, the only reason I’d need to add another scene is for a start-up screen.
And there’s no reason for me to use any previously used variables in the actual game scene, unless it’s something vague, like a repeatIndex variable that I’d use for multiple things.
I’m trying to do more complex saving in my newer game, so what’s stopping me from changing all of my scene variables to global ones?
Is there a downside for me?
I already know how to convert all of my object variables into its own save, and that’s pretty easy to do, but the I thought that changing all of the variables to put it into an array/structure, and then changing the events, and all of that would be a bit annoying.
Wouldn’t it be more beneficial for me to simply replace each scene variable with a global variable with the same name, and if I’m correct it would maintain its functionality, right?

1 Like

This is excellent example of struggle we all gonna have or had in dev process
And whatever any1 will reply you with including what i am about to write take it as OPINION not as as way to go
Cause we all need to bend logic to our needs and habits and not like there is clear and right answer here

For me answer is
I have 3 levels of how much do i care for variables
1 - “you can go to hell” variable is is so useless to me i do not care what will happen with it and then its for me in 1st place object variable
And if that does not suit my needs its scene variable
I do not need to to care if its preserved between scenes
I don’t even need to care if its constantly existing in a scene and not to litter my variables window list i go with object variable
Something like bar to indicate charging for example
Like charge shot or when fishing bar shows how strong will be your throw of a bait
THAT can totally be object var cause it only need to exist when i am fishing or charging something cause that objects NEEDS to exist in that exact moment
So if that object is deleted later (variable won’t exist anymore) i could not care less

2 - “you are here only cause you serve some purpose but you still can go to hell”
Scene vars like index/climb increasers for something i need to repeat
Like creating grid of some objects or spawning objects with +1 ID variable to previous object
It cannot be object var cause i would need constantly to have one object to keep track of such var so it could not be deleted
BUT i still don’t care about it to the point even if it won’t exist between scenes i won’t cry

3 - “I would see you in hell but i actually need you always”
Global vars that i NEED to exist between scenes
Like volume for music/sound
HP/lives/attack/progress/background color/AND ALL other info that is essential to always be maintained no matter where are you (in which scene) and need to always exist

BUT now after reading point 1 you may ask why i don’t always go with object vars?
Object vars require you to provide longer name than scene vars
For example ObjectName.VariableName vs just VariableName

So Player.ChargeLevel vs ChargeLevel
Object vars are longer and that is not so big problem
UNTIL you gonna try to make formulas/equations with them
You will generate long formulas to calculate stuff ending up with something that need 2 or more lines to fit your screren
Even more if you are on mobile

And your goal should be not to have Health variable but HP variable
Not XPosition variable but XPos
You really want short names cause in long run it will help you just look at your events and vars and instantly understand what is going on
When if you would have LONG NAMEEEEEEES it will take you longer to go like “ow this is this and that is that so in combination it means its doing something else”

As for point 2 and 3
Keep in mind that you can change scene to same scene you are in
And now you just restarted your scene AND its scene vars
BUT when you have global vars there you would wish to restart you need to restart them manually like set them to some values at beginning of scene or in event where you restart your scene

But why you would do that?
Well something like enemy HP should be object variable cause you do not care about it
But player HP should not be object neither it should be scene it should be GLOBAL variable
It does not make sense when it comes to the fact it is something meant just for player object so it should be this objects variable

BUT when you think about HP as value you want to exist between scenes and maintain its value without you preforming save/load between scenes
Then global variable for ANY player stat HP/Armor/Ammo/Mana/WHATEVER makes a lot more sense

But there is one more type of variable worth mentioning
Local variables
Look local vars DO NOT maintain their values each frame
So like you set local variable called FakeVar to 5
And now in sub event under it you add one 4 to it
Then in until frame on which you added 4 to it will end
FakeVar will be 9 but will be back to 5 as soon as new frame starts
CAUSE NOTHING is maintaining local variables values there
They are created each frame in their event and set to whatever you set them in your event

And that is BS you may ask how that is even useful?

Well imagine you have movement for player with forces
BUT you need 4 SEPARATE/INDEPENDENT events for each direction
YET you need same value for speed
So how about make local variable called Speed
Add action to set it to 70 and now instead of providing speed in your movement events you set there Speed variable
AND NOW if you move too slow or too fast
You adjust that value ONLY in one place in that action to set value for Speed variable
Instead of replacing static number in 4 different events
Where there are more applications but by now you should get the idea
You did not litter anything since local vars exist only in events in which they are used in
And so you can have 1000 local variable events
And they won’t see each other cause like i said they exist only inside their own events

So all that combined now you should decide what is your path/way of doing things

These are my rules for how to handle vars
And not best way
Well best way for me but is it best way for everyone? I would highly doubt that

Also this may sound stupid but i NameMyVariablesWithEachWordBeingCapitalLetter
And that is one golden rule i never break

I never have health or attack variables or playerxposition
Its always Health Attack and PlayerXPosition
Where when it comes to short names like hp instead of health points
Its HP or id ID all caps there

Anyway this should help you decide do you want to go with global or object vars
In my case its matter of go global if you will eventually need them between scenes
If not then keep it as scene

1 Like

Hi ZeroX4!

We can say you like writing but also well explain the things.

Are you sure of that? but i have also not tested.

Xierra

That is explicitly how local variables work, yes.

They only have the calue set for the duration of the event, so if the event is reevaluated next frame, the variable is reset to the default value for it.

Ok, thanks.
So, that can create strong headaches, in case of bugs in the games.

Xierra

The main point was that I don’t use other scenes in my games, and if I do, it’s always not using other variables I’ve previously used, I’d have no problem with global variables, and it just seems so convenient, you can only use global variables to save the game, like when a player closes the tab and comes back.
So would it be beneficial, or even worse to put everything in one structure variable and save it with that as well as change the variables from the events?
Or am I misunderstanding how saving works?
Also I do also make all of my variables capitalized with every letter of the first word.

Capitalizing 1st letter was just example
I saw ppl go player_health or can_dash
For me its PlayerHealth CanDash
Like YOU need to find your own way of doing things
Something that makes sense to you that instantly just by looking at it will tell you what is going on without you needed to deduce what is what

And your point is invalid
You don’t use other scenes TODAY and how you know you won’t use other scenes ever?

And there is no difference between global and scene vars when it comes to saving
You can save/load EXACT SAME WAY scene as global vars
Is it number var a boolean or structure or array
That makes NO difference at all

Technically if you gonna save some set of variables
It makes perfect sense to shove them in under structure/array and save that
But will it be scene var or global var only plays role of what i described in my previous message
Global vars exist between scenes but do not reset when you change scene to same scene
On other hand you say you don’t use other scenes
Really?
You have no separate scene for menu/title screen?
Cause if you do you cannot load from that
You would need to load from scene in which you play if you go with scene vars

Bottom line
Only thing you need to consider when picking between scene and global vars
Global var can be loaded in any scene and will not reset if you change scene
So you need to consider where you will load what
Maybe scene vars would be better idea if you wish to reset some stuff

I personally and i put pressure here on word ME
Have mix of global and scene vars
Like i said something like player stats or volume or whatever i need to exist constantly is in global structure var so i can easily save it
But stuff like enemies HP or idk some variable i use for charge will be scene var
Like imagine making wave defense game
Wave number should be scene var so i can reset it by changing scenes and something that SHOULD NOT be saved when performing a save
So it should not be in structure var i use to save

And regardless on that
Scene and global vars do not have any difference that you should care about
Like you reference their names in exact same way in events
So other than from icon next to them you won’t be able to tell which is which
Like for you it does not matter

And idk if that was clear
But everything you actually gonna save/load
Should be under structure
Maybe not one but few
For example something like player actual save state should be separate structure
From player settings like audio or key binds

Like i make 2 structures (sometimes more)
SaveGame
SaveSettings

These are my 2 structures
Game holds player progress
Where settings well i let you guess what this one holds

And i have strong feeling you have some bad understanding of vars when i read your question is it beneficial or worse
This you should explain cause idk if my explanation hit your itchy spot

1 Like

I’m sorry.
I don’t like it when people say I have a bad understanding of something, that was a bit rude.
It was all a misconception, you see.
I thought you could only save GLOBAL VARIABLES into a JSON to save and reload it.

When someone is trying to explain something to you to teach you something
So you can understand what is going on
And is telling you the truth

You calling it being rude?

I gonna block you so i never reply to you again by accident and you won’t ever feel i am rude towards you

We all do the best we can with the English language skills we have. What if ZeroX4 had instead said ‘And I have a strong feeling you have a misunderstanding about variables.’ I personally think either version is fine and I’m constantly amazed at how well people with multiple languages communicate.

I dunno what you think…but my rule is…
use global for something permanent…use anything else when don’t…
globals stays in memory everytime…instead you may need a scene var for an object event that last for an event until the object is deleted…
put this into as globasl is not …convenient…
…also there are many extensions or actions that needs scene var…like raycast…

so i guess in the end you gonna have both kind of vars anyway…

the new var method basically suppressed objects vars…one day we may gonna have only globals…
…but not now…

I’m sorry, I try to stay out of drama, but I felt that you saying you have a STRONG feeling that I have a bad understanding of variables was rude, because it felt like you were insulting my intellect.
Blocking someone to resolve a simple and easily resolvable conflict is not the way to do it, and I hope you understand this.
Even though you’ll most likely never see this message, hopefully it gets around to you some way or another.
Misunderstandings happen a lot on the internet with emotions being conveyed wrongly, and especially with foreign English speakers, it can be difficult.
I truly understand this and I am sorry for my little comment, but you are just as guilty.
I’m going to get rid of my notifications from this post and leave it alone.
I hope you have a nice day.

I also don’t want to sound rude but if a post on the web is enough to offend your intellect…your intellect is already faulty at the core.
Also If you’ve been here for a while, you would have noticed that Zero is one of the few who takes the necessary time to explain things. You would have noticed it from the length of his posts. Thinking that someone who dedicates to this could be rude is understandable, but offensive? Lol. You’re way off track.

1 Like


I didn’t turn off my notifications because I didn’t deem it to be completely necessary, but now I’m definitely going to, I again, don’t want to cause more drama, and based on you not leaving this alone, I will tell you… stop siding with Zero, and stop responding to this post, not even to respond to this.

I’m only going to say to defend myself.
I never said anything about it being offensive, just rude, you seem to be failing to see the positive side of the response, and, I presume, are only responding to cause further drama, please realize the fact that I’m trying to walk away, and realign your intentions.

You do sound rude. “Already faulty at the core,” “Lol,” all of these are rude in the context of this.

I do notice Zero puts effort into his posts, he really does, I was simply trying to point out what I thought was rude and that I thought his response was a bit of an overreaction.

Just to reenact my previous statement, this post is simply to clarify my feelings about what had happened, and not to cause anymore drama or feuds on this forum.

For the good of this forum, I will refrain from posting if any drama that directly correlates to me happens in any other post for a few months, and will immediately flag anyone who tries to bring up this post again for harassment, including you.
You reporting me would also be invalid due to this being MY post.

Goodbye. Please leave this post alone, and all other posts that Zero and I are in if it relates to this topic.

Your “strong feeling” comment was not a truth. It was an unneeded opinion. Be careful about conflating the two.


Insults like this are unnecessary to this thread. Especially when someone has a misunderstanding of a topic.

BTW, using the word ‘but’ in a sentence like that is effectively saying “ignore what’s just been said, what’s about to follow is what I really mean”.


That doesn’t justify what could be construed as more personal attacks or gaslighting. Just because someone doesn’t grasp a topic as quickly as you think they should, or has misunderstood a topic, doesn’t justify disparaging them.


No, it’s not. Common courtesy, politeness, respect and patience are the expectations. I don’t understand why rudeness should be acceptable. Consideration should be a must, since many members here are non-native English speakers.

2 Likes

I’m not gonna start arguing here so this will be my last input in this topic

I remember when one user attacked you cause you arrogantly DID NOT provide screenshots of how logic should look in events
Instead you were explaining it via text in posts
To the point that user made separate topic about you that when he asks for help he would expect SCREENSHOTS
And was trying to name-shame you for not providing ones

That just keeps me true to my claim that some users come here to get help and some comes here to be offended cause they can

I block such users cause if it happen to you it could happen to any of us
And i strongly believe NO ONE HERE deserves to be insulted for trying to provide help
SO when i see user insulting person providing help its first and only indication i need to block such user

When OP alone admit he think something is meant just for one purpose when in reality it can be used for many things (global vars) then its a fact such person have bad understanding of it
So i can hardly see it was my opinion more than it was actual fact admitted by OP

Each time a user tell me i am rude each time moderation needs to jump in to tell me i am rude
I wonder what im still doing here?
Cause i speak to EVERY SINGLE USER SAME EXACT WAY
So in the end turns out i could and should be banned for any reply to any user i ever made

And most of us don’t have english as our 1st language that’s a fact
But that does not justify trying to attack someone
We still have common sense
When i see any user trying to help here another i often read sentences or even words i do not understand
Some even making it look like helper is attacking question asker
And yet it turns out if i use common sense and try to deduce meaning of what person helping was trying to convey i find out that my assumptions were wrong about it being rude

When my girlfriend is in shop with me and she finds like hats of frog or hamster or cat or you get the idea by now and she ask does she look cute with it on
I tell her
Alice i don’t want to insult you “but” you just look stupid in it
Which is me trying to say
Even if you think my answer is insulting or will just feel like it is
I do not mean to insult you or feel bad so take it just as my point
And not as me trying to hurt you
So i hardly see how using “but” negates what was written before it

And lastly i would NEVER expect any special treatment neither would i want any and i think no one should

Again this is just matter of common sense and not
OW you made 1000 posts you helped 3423855 ppl i need to now bow to you
ABSOLUTELY NOT

Ppl come here to ask for help
There are other ppl that comes here to provide it
(NOT TALKING ABOUT MYSELF HERE) if such ppl want to help
For me its even hard to assume they come here to make someone feel bad when in the first place they come here to make someone feel good
Like that feeling you get when you solve someones problem
And even so you don’t see their face you do not hear them
You know smile is not going down from their faces and they are jumping like monkey from the joy of impossible issue turned out to be very possible to solve problem

@RMDB Thank You for trying to defend me i do appreciate it like i really do these are not just empty words
It really means A LOT to me
But never do it in the future
I do not need to be defended
If at least one user understand i am here only to help and not to make any1 feel bad
That one user is more than enough for me even if all other users would say i am just here to make ppl feel bad and insult them

First thing
I understand your point…totally.
And i’m not defending zero particularly, i’ve just seen his first answer and i posted based on that.
I would have wrote the same for ppl like you,keith,silver,davy,magicsopha,…
ecc…

i mean…i can’t understand how ppl could be offended by an explanation (Even if rude words are used as long they’r not insults) if the same ppl take the time to help you at first…

but thaz ok too, if these are the rules …

Nowadays, not even teachers can slap students without receiving a reprimand