otterZ
Member
What is the best practice for initializing global variables when also (almost simultaneously) reading them from an INI file?
For example, I have an object called 'obj_first_room_controller', where I am initializing global variables at the start of the game in the Create Event. I also have code in that same Create Event to read INI files fetching the value of those same global variables.
For example:
So, here are a few questions for what is the best pracitice:
* Do I need to declare and initialize a global variable if I am reading them from an INI file that will do kind of the same thing anyhow? It does make it more readable if I declare and initialize them first though. Plus I'd feel oddly uncomfortable leaving it to the INI file code to initialize them for some reason.
* Should I use true/false, noone or -1 when initializing a global variable when the INI file will write over it anyhow, or does it even matter?
* Should I have the INI read code as a separate object even?
* This object is in a persistent First Room, but would other GM users usually initialize global variables in a Game Start Event?
(Please note that I did not initialize the variables in Room Start, as I only want them accessed at the very start of the game.)
I am starting a new project and this time I want to take the time to code a bit more elegantly, and make it more readable, rather than work/code like a maniac into the early hours with an 'if it works . . . whatever' type attitude.
For example, I have an object called 'obj_first_room_controller', where I am initializing global variables at the start of the game in the Create Event. I also have code in that same Create Event to read INI files fetching the value of those same global variables.
For example:
GML:
// This code is in the Create Event in the first room controller object
// Initializing global variables
global.magic = noone;
global.weapons = noone;
// Reading INI file values
global.magic = ini_read_real("savegame", "magic", true);
global.weapons = ini_read_real("savegame", "weapons", false);
* Do I need to declare and initialize a global variable if I am reading them from an INI file that will do kind of the same thing anyhow? It does make it more readable if I declare and initialize them first though. Plus I'd feel oddly uncomfortable leaving it to the INI file code to initialize them for some reason.
* Should I use true/false, noone or -1 when initializing a global variable when the INI file will write over it anyhow, or does it even matter?
* Should I have the INI read code as a separate object even?
* This object is in a persistent First Room, but would other GM users usually initialize global variables in a Game Start Event?
(Please note that I did not initialize the variables in Room Start, as I only want them accessed at the very start of the game.)
I am starting a new project and this time I want to take the time to code a bit more elegantly, and make it more readable, rather than work/code like a maniac into the early hours with an 'if it works . . . whatever' type attitude.