• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Save game problems (again)

Le_Beholder

Member
Well it's that time again. Either I power through this, or give up and come back a month or two later.
I'm trying to figure out how to save my game properly, and I've heard of several methods:

Writing to ini files, or using ds_map.

I tried the former with no success.
I get the concept pixelated pope talked about but I think my problem is that I have two different menus in two different rooms for ds_map to be effective, maybe I missed something or still have little clue how to properly implement it...
I just need to save the players hearts, heart containers, bombs, and location as a start.

Also ive moved on from GM8.0 because it's rapidly becoming obsolete and game_save() does not work with the new bell and whistle scripts I'm trying out for my new game. namely, scripts for animated tiles by again, pixelated pope.

What should I try and how can I go about it?
 
Last edited:

Rob

Member
What code did you use for .ini saving?

Saving
Code:
ini_open( 'savedata.ini' );
ini_write_real( 'save1', 'score', score );
score = ini_read_real( 'save1', 'score', 0 );
ini_close();
Loading:
Code:
ini_open( 'savedata.ini' );
score = ini_read_real( 'save1', 'score', 0 );
ini_close();
This is the code from the manual and if you put it into 2 scripts and call them at the right time, you should be able to change/save/load "score"

If you have been using this code then maybe you are over-writing the variables you want to save after you loaded them? Eg You load a game, run the load script and then initialise the variables all over again from within an object, resetting them to the original values.
 

chamaeleon

Member
What should I try and how can I go about it?
If you have a problem adding loading and saving to an existing game you're working on, may I suggest starting a new project for the purpose of exploring how to use the ini functions or ds_map saving in conjunction with perhaps json encoding and decoding until you feel comfortable with how to use them? Doing this will also allow you to share code easier as you won't have as many dependencies on your actual game that would force helpers to implement something themselves if they want to try it out rather than just typing a comment and hope it's correct.
 
  • Like
Reactions: Rob

Le_Beholder

Member
I'm trying ini saving this time around, my first attempts were with ds_map.
And as far as projects go, this is the practice game I'm trying to.. practice on.

So far the same problems persists, because I have a title screen object in its own room first, loading a game doesn't work, even when I've set all the values I want to keep as globals, and putting the player object in the tile room is wouldn't do either for many other reasons that this project despite being for practice, still has too many things tied into it.

The only thing I could think of to knock past these fatal errors is to put the title object gui panel into the same room where the rest of my game is, and somehow wrangle things from there.. like making the camera object focus on it first before the player for instance, and possibly making a pause state for the player, or just setting him to his existing "idle" state until after I select load game or new game from the title object...

And then there's collision's for the player that impact the data I'm trying to save in the first place, my collision code for hearts as an example:
Code:
with (other)
{
other.hp = Max(other.hp + hp, 0, other.hp_containers);
Instance_destroy();
}
If I don't put the title menu object into the same game room as the player, I'd have to somehow set that to function with global variables instead of local.

I'll post back with code if something works.

Edit:
I just had an idea..
I could try setting up a global.loading variable to be set to true or false for the tile menu object, and then have my control object check it after the room switch, and Then maybe run the loading script.
I'll try that later after work.
 
Last edited:

chamaeleon

Member
All of your text seems to indicate some lack of understanding of the fundamentals. I don't mean to be mean when I say that. Just, nothing you wrote says it is saving and loading specifically that is the problem. You should not have any issues using multiple rooms with persistent objects carrying data along when you switch rooms for instance, but instead you say you need to have an instance in the same room as the player. That is not true at all, under the right circumstances. Other circumstances may dictate you do, but it all comes down to specific requirements.

In any case, if you haven't already try to create different objects for different tasks. You mention a title screen object needing to be in a non-title room. That simply means you have put some functionality and data in it that should be separated out into its own object. That is, have one or more title screen objects for managing that display, along with data or state objects that are persistent over all rooms, etc.
 
Last edited:
R

robproctor83

Guest
@Le_Beholder I'm not sure if you realize this but switching rooms is like playing a different game. If your in Room A and then go to Room B as far as things are concerned it's two different games and things you create in the first room are no longer accessible in the second. In order to make things pass from one room to another you have to make them persistent, it's a property look it up if your not sure about it. That will work for the time being, but you should get the ini saving/loading working as that is the right way.
 

Le_Beholder

Member
alright. my idea using a global variable to start the save/loading after switching rooms worked. now the last problem is seeing why it nukes my players health whenever i do a save.. but im sure thats another topic elsewhere, and i do realize i came off all whiny in this post because i really was frustrated with it at first. and i pretty much didn't know what kind of answer i wanted from you kind people anyhow so. just. thanks for now, this post is getting marked solved..
and i wish to forget this post ever existed now. such is life.
 
Top