this post was submitted on 06 Jul 2025
18 points (100.0% liked)
programming
258 readers
3 users here now
-
Post about programming, interesting repos, learning to program, etc. Let's try to keep free software posts in the c/libre comm unless the post is about the programming/is to the repo.
-
Do not doxx yourself by posting a repo that is yours and in any way leads to your personally identifying information. Use reports if necessary to alert mods to a potential doxxing.
-
Be kind, keep struggle sessions focused on the topic of programming.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Definitely ask yourself whether they really need to be, but using a global variable makes sense if it's something that's going to be used by a large number of different parts of the program.
For example, the game I'm developing uses a variable called
control_mode
to determine how to handle the player's button presses. Anything that can be affected by those button presses (the player avatar, the menus, etc.) needs to be able to know the game's current control mode to be able to handle user input, so e.g. the player character shouldn't be able to move during cutscenes or when the game is paused. Since so many different parts of the program need to readcontrol_mode
, I made it global, but I only change it from a dedicated control manager.