Nixxi
Member
Hello GameMaker Community.
I'm having an issue with creating global variables for sharing information between the players, game objects, and ini reading/writing. Part of the problem is that my game has a max of twenty (20) save slots, each slot has roughly 5,200 individual datapoints (for stats, records and progression, inventory, etc.), and if I can't get them created/initialized using 'for' loops and concatenated strings I'll need to refactor the whole game or be forced to write 103,360 individual variables - and who knows how many errors and carpal tunnel-related doctor visits that will result.
So what I'm hoping is that I can show you my little batch of code that should initialize all these variables and someone will recognize what I'm doing and show me the correct way to do it because it's currently just not doing anything. Any help would be very much appreciated.
Here's my code:
Quick breakdown:
d = Number of Saved Players
i = Number of data points for non-inventory related things (name, score, xp, currency, name, color, character customization, etc.)
g = Number of gear groups (helmet, chest, gloves, belt, etc)
n = Number of inventory slots in each gear group
v = Individual stat values for each gear item
ss##_ISLOCKED and ss##_ISLOADED are for ensuring data is being saved in the correct corresponding save location and can't be overwritten by anyone else once a player has loaded the save onto their character.
When I run this in the debugger, all of my individually initialized globals (like global.i_SaveSlots) are present, but none of these variable_global_set functions seem to work - I can't find or reference any of them and they're not presently listed in the global variables list. So, does anyone have a good alternative to this (preferably not using 'ds_list/maps/grids' because I can never get them to work right and they scare me) so I can salvage my project?
I'm having an issue with creating global variables for sharing information between the players, game objects, and ini reading/writing. Part of the problem is that my game has a max of twenty (20) save slots, each slot has roughly 5,200 individual datapoints (for stats, records and progression, inventory, etc.), and if I can't get them created/initialized using 'for' loops and concatenated strings I'll need to refactor the whole game or be forced to write 103,360 individual variables - and who knows how many errors and carpal tunnel-related doctor visits that will result.
So what I'm hoping is that I can show you my little batch of code that should initialize all these variables and someone will recognize what I'm doing and show me the correct way to do it because it's currently just not doing anything. Any help would be very much appreciated.
Here's my code:
Code:
for (var d = 0; d < global.i_SaveSlots; d += 1) {
variable_global_set("ss"+string(d)+"_ISLOCKED",0); // Save Slot is occupied
variable_global_set("ss"+string(d)+"_ISLOADED",0); // Save Slot is currently loaded
// Create Player Profile, Records, and Base Stats
for (var i = 0; i < 16; i += 1) {
if i <= 2 {
variable_global_set("d"+string(d)+"_PlayerProfile"+string(i),noone);
} else {
variable_global_set("d"+string(d)+"_PlayerProfile"+string(i),-1);
}
variable_global_set("r"+string(d)+"_PlayerRecord"+string(i),-1);
variable_global_set("s"+string(d)+"_PlayerBaseStats"+string(i),-1);
}
// Values for p_GearSlot0#[#,#] - 8 Slots, 16 Items per Slot, 40 stats per Item
for (var g = 0; g < global.i_InventoryGroups; g += 1) { // Gear Group
for (var n = 0; n < global.i_InventorySlots; n += 1) { // Gear Slot Number
for (var v = 0; v < global.i_InventoryStats; v += 1) { // Gear Stat Value
variable_global_set("i"+string(d)+"_Gear0"+string(g)+"_Slot"+string(n)+"_Stat"+string(v),-1);
}
}
}
}
d = Number of Saved Players
i = Number of data points for non-inventory related things (name, score, xp, currency, name, color, character customization, etc.)
g = Number of gear groups (helmet, chest, gloves, belt, etc)
n = Number of inventory slots in each gear group
v = Individual stat values for each gear item
ss##_ISLOCKED and ss##_ISLOADED are for ensuring data is being saved in the correct corresponding save location and can't be overwritten by anyone else once a player has loaded the save onto their character.
When I run this in the debugger, all of my individually initialized globals (like global.i_SaveSlots) are present, but none of these variable_global_set functions seem to work - I can't find or reference any of them and they're not presently listed in the global variables list. So, does anyone have a good alternative to this (preferably not using 'ds_list/maps/grids' because I can never get them to work right and they scare me) so I can salvage my project?