[SOLVED]Resource order and saving

Pfap

Member
This is probably not a big deal, but is there a solution to avoiding resource conflicts when updating a launched game other than: once a game has been released never change the order of resources and if adding to the game only add at the tail of the tree? I guess, maybe saving the string name and then using asset_get_index? And to save the index used in game use sprite_get_name(players_selection) and save the string? I think I may have just solved it while writing this post... except it won't really work for html5, and I'm curious to see if anybody else has any ideas or solutions they have used.
 

CloseRange

Member
perhaps I'm out of the loop but why does maintaining the asset index matter? Usually when a game is updated the only thing that matters staying static/unchanged is the save files. A game loads the file, reads information like position, gold, experiance, ect. Then moves the room/creates objects/changes variables depending on what it reads from that save file.
The object order/index shouldn't conflict with that because when you write:
instance_create(x, y, obj_player);
it compiles and updates the 'obj_player' to be whatever object index you truly meant.

When updating a game it should also update what the index was based on what files you changed.
Unless you are doing something special with the asset index's? Other than that I never had problems updating games.
 

Pfap

Member
perhaps I'm out of the loop but why does maintaining the asset index matter? Usually when a game is updated the only thing that matters staying static/unchanged is the save files. A game loads the file, reads information like position, gold, experiance, ect. Then moves the room/creates objects/changes variables depending on what it reads from that save file.
The object order/index shouldn't conflict with that because when you write:
instance_create(x, y, obj_player);
it compiles and updates the 'obj_player' to be whatever object index you truly meant.

When updating a game it should also update what the index was based on what files you changed.
Unless you are doing something special with the asset index's? Other than that I never had problems updating games.
Yea, I didn't even think about it until it became an issue. Especially, if you have more than 1 person on a project or frequently use the duplicate sprite or any asset that just increments the resource tree instead of adding to the tail.

Code:
global.players_choice = ini_read_real("avatar", "animation", my_cool_animation );
show_debug_message(sprite_get_name(global.players_choice));
global.players_choice = my_cool_animation;

my_cool_animation was returning 85, because my resource tree had been incremented or a resource had been dragged and moved to a new position. I wanted to draw the sprite indexed at position 86, but it was drawing the one indexed at 85. Which at the time of saving was the correct index.
 

TheouAegis

Member
If you aren't going to maintain resource indexes, then you will need to save something other than the resource indexes. You could save the resource names and then use asset_get_index() as you figured, but just make sure you never change the names of any of those assets that could possibly be saved. Or you store pseudo-index and use those pseudo-indexes in a switch or temporary array to assign resources based on the pseudo-index; since you're not saving resource IDs or names at that point, changing the resources wouldn't affect the save files.
 

TheouAegis

Member
perhaps I'm out of the loop but why does maintaining the asset index matter? Usually when a game is updated the only thing that matters staying static/unchanged is the save files. A game loads the file, reads information like position, gold, experiance, ect. Then moves the room/creates objects/changes variables depending on what it reads from that save file.
The object order/index shouldn't conflict with that because when you write:
instance_create(x, y, obj_player);
it compiles and updates the 'obj_player' to be whatever object index you truly meant.

When updating a game it should also update what the index was based on what files you changed.
Unless you are doing something special with the asset index's? Other than that I never had problems updating games.
Suppose the game is going to save the state of the room as well and that room has randomly generated NPCs or items. How will he tell the save file what types of NPCs or items are in the room if he doesn't save their asset indexes or names? If he stores the asset indexes, then changing the order of resources in Game Maker will corrupt the save file. If he stores the names of the resources, then changing the name of a resource will corrupt the save file.
 

Pfap

Member
If you aren't going to maintain resource indexes, then you will need to save something other than the resource indexes. You could save the resource names and then use asset_get_index() as you figured, but just make sure you never change the names of any of those assets that could possibly be saved. Or you store pseudo-index and use those pseudo-indexes in a switch or temporary array to assign resources based on the pseudo-index; since you're not saving resource IDs or names at that point, changing the resources wouldn't affect the save files.
That's a good idea I had not thought of a pseudo index. Hmmm... I'm trying to think of how to set that up, can you iterate through the full resource tree? Or would that need to be set up manually?
 

CloseRange

Member
Suppose the game is going to save the state of the room as well and that room has randomly generated NPCs or items. How will he tell the save file what types of NPCs or items are in the room if he doesn't save their asset indexes or names? If he stores the asset indexes, then changing the order of resources in Game Maker will corrupt the save file. If he stores the names of the resources, then changing the name of a resource will corrupt the save file.
I guess that's true. I always just saved it under an enum or some way to remember it so I didn't think about that.

Also to iterate through a full resource tree:
Code:
for(i=0;object_exists(i);i++){
    if(i == object1) {
        //do something?
     }
}
that should work for iterating over every object at least
 

TheouAegis

Member
You would need to set up the array or switch manually. Looping through the resource tree would just put you right back where you started.
Code:
var res_spr;
res_obj[0] = obj_frog;
res_obj[1] = obj_cow;
res_obj[2] = obj_dog;
//and so on
//Then in your loop that reads the ini file...
//get the variables from your ini file or whatever
/*let's say xx=x, yy=y, and ind=pseudo-index*/
instance_create(xx,yy,res_obj[ind]);
With something like this, it wouldn't matter if you changed the order of the resources. The file would be more cryptic since it would be a number and not an actual resource name. Likewise, the file could be a bin or dat file rather than an ini or json since all you would need to store are integers anyway. If you changed a resource name, you would get an error if you don't change the array (or switch if you opt for the switch method), but then that's on your programmers, not a fault of the save file itself.
 

Pfap

Member
You would need to set up the array or switch manually. Looping through the resource tree would just put you right back where you started.
Code:
var res_spr;
res_obj[0] = obj_frog;
res_obj[1] = obj_cow;
res_obj[2] = obj_dog;
//and so on
//Then in your loop that reads the ini file...
//get the variables from your ini file or whatever
/*let's say xx=x, yy=y, and ind=pseudo-index*/
instance_create(xx,yy,res_obj[ind]);
With something like this, it wouldn't matter if you changed the order of the resources. The file would be more cryptic since it would be a number and not an actual resource name. Likewise, the file could be a bin or dat file rather than an ini or json since all you would need to store are integers anyway. If you changed a resource name, you would get an error if you don't change the array (or switch if you opt for the switch method), but then that's on your programmers, not a fault of the save file itself.
Thanks that seems like the best solution. It would really brick the game pretty bad if it was saved under a string that no longer existed, so it's probably best to avoid saving the string and using asset_get_index().
 

NightFrost

Member
On a related matter: if backwards compatibility with save files becomes too large a problem to maintain, you can add backwards incompatibility. Insert a "save version" number to the save file, and the game has a minimum version number it will load. Whenever something changes in saves, you bump up the version number and prepare a compatibility script to bring in older version. Or you declare that saves older than version N are no longer supported and won't be loaded. This goes over best in games where you frequently start a new game... (For example grand strategy games from Paradox occasionally break compatibility with older saves when systems are given a fundamental overhaul.)
 

Pfap

Member
On a related matter: if backwards compatibility with save files becomes too large a problem to maintain, you can add backwards incompatibility. Insert a "save version" number to the save file, and the game has a minimum version number it will load. Whenever something changes in saves, you bump up the version number and prepare a compatibility script to bring in older version. Or you declare that saves older than version N are no longer supported and won't be loaded. This goes over best in games where you frequently start a new game... (For example grand strategy games from Paradox occasionally break compatibility with older saves when systems are given a fundamental overhaul.)
Thanks for posting.
 
Top