Jump to content


Photo

Load game problem


  • Please log in to reply
6 replies to this topic

#1 KevinBlazeCoolerz

KevinBlazeCoolerz

    GMC Member

  • GMC Member
  • 111 posts
  • Version:GM8

Posted 18 June 2012 - 04:24 AM

in Game Start Event, I use this code:

game_load("file.sav") //this is executed by GM

//but below all not be executed / not work
global.tool = 1

ini_open('game.ini')
if ini_key_exists('VF','VFft')
{
global.ft = ini_read_real('VF','VFft',0)
global.rtime = global.curtime - global.ft
}
ini_close()

I know the problem in "game_load", when game_load executed, so all code are not read by GM.

so what will I do to make all my code executed by GM ?
  • 0

#2 slayer 64

slayer 64

    GMC Member

  • GMC Member
  • 3278 posts
  • Version:GM8.1

Posted 18 June 2012 - 04:48 AM

well first, stop blaming game maker for something you did because game_load is probably working perfectly. throw in some more checks to see if your code is proper.
game_load("file.sav")

global.tool=1

fname="game.ini"

if file_exists(fname)
{
    ini_open(fname)
    
    if ini_section_exists("VF")
    {
        if ini_key_exists("VF","VFft")
        {
            global.ft=ini_read_real('VF','VFft',0)
            global.rtime=global.curtime-global.ft
        }
        else
        {
            show_message("VFtf key doesn't exist")
        }
    }
    else
    {
        show_message("VF sections doens't exist")
    }
    
    ini_close()
}
else
{
    show_message(fname+" doens't exist")
}
if game_load is being retarded, which some game maker functions can be, a lot like instance_destroy or room_goto. i think game_load might take an extra step to actually happen. try setting an alarm and reading your ini file later. i don't use game_load ever because i think it's a turd anyways.
game_load("file.sav")

alarm[0]=1

alarm[0]
global.tool=1

fname="game.ini"

if file_exists(fname)
{
    ini_open(fname)
    
    if ini_section_exists("VF")
    {
        if ini_key_exists("VF","VFft")
        {
            global.ft=ini_read_real('VF','VFft',0)
            global.rtime=global.curtime-global.ft
        }
        else
        {
            show_message("VFtf key doesn't exist")
        }
    }
    else
    {
        show_message("VF sections doens't exist")
    }
    
    ini_close()
}
else
{
    show_message(fname+" doens't exist")
}
and wtf kinda variable names are VF and VFtf suppose to be? are you some kinda lazy typer and can't type a few more characters? christ
  • 0

#3 xYorYx

xYorYx

    Vampire

  • GMC Member
  • 83 posts
  • Version:GM8

Posted 18 June 2012 - 07:37 AM

stop blaming game maker for something you did because game_load is probably working perfectly

if game_load is being retarded, which some game maker functions can be

Uhm, what? And some people prefer to have shorter names for most parts of the code. For example I have seen button_press_check to be written for short as BPS. As long as the programmer understands the code its fine to use any name, and if he is working with other people there are comments. i really don't see a reason to be so rude with the topic creator, he was just asking for help.
  • 1

#4 Noele

Noele

    GMC Mentor

  • GMC Member
  • 2359 posts
  • Version:GM8.1

Posted 18 June 2012 - 03:06 PM

When a saved game is loaded execution resumes on the next execution step NOT the next execution instruction.
E.G.
game_save("my_game.sav");
show_message("Game Saved");
room_goto(menu_room);
When the saved game is loaded the show_message part does not get executed and the loaded game does not go to another room. Instead execution resumes on the next eventstep. Remember too that create events are executes once upon creation and since all instances in a saved game already exist, their create events are not executed again.

All quite logical when you think about it.

One solution is to create an update object to load or execute whatever you require in its step event. Create an instance of it before saving and destroy it right after.
E.G.
instance_create(0,0,obj_game_update);
game_save("my_game.sav");
instance_destroy(obj_game_update);
obj_game_update will exist in the loaded game so its step event can execute the code you want before destroying itself. Simple but generally effective.
  • 0

#5 KevinBlazeCoolerz

KevinBlazeCoolerz

    GMC Member

  • GMC Member
  • 111 posts
  • Version:GM8

Posted 19 June 2012 - 11:25 AM

@slayer 64: I think no problem with my *.ini file script, cz if I don't use load_game, it's work perfectly.
VF is my game's name, but I just use the initial of the title of my game

@xYorYx: hehe, that's true

@Noele: come on guys, it's not a save_game, but load_game,, I think and I'm sure if save_game always work in this problem

still not solved, Please help me guys :thumbsup: :thumbsup:
  • 0

#6 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 19 June 2012 - 12:32 PM

@Noele: come on guys, it's not a save_game, but load_game,

Read carefully and you will realize he discusses about game load even though the example code uses game_save. And actually, the solution to your problem involves game_save, as discussed later.

He is right about that game_load doesn't immediately take effect. The actual loading takes place at the end of the current step (as mentioned in the manual, right above the description of game_load.) So, what is actually happening is:
  • You execute game_load (the actual loading doesn't take place here!)
  • You read global variable from the ini file
  • After that, Game Maker actually loads the file, resetting all of variables set in the step (2).
Your codes were actually executed, but immediately got overwritten with values in the saved game.

On the other hand, game_save takes place at the right moment it is executed. Here is the trick: you can save something in the file and reset it in the game so that it only takes effect when the game is loaded. For example, you can set an alarm in the saved game.
alarm[0] = 1;
game_save("file.sav");
alarm[0] = -1;
The alarm doesn't actually go off in the game, because it is reset to -1 instantly. However, the alarm is saved in the file. When you load the file, the alarm will be turned on when the loading actually takes place. You can use it to trigger loading the ini file. Now, the loading code becomes a single line:
game_load("file.sav");
// Loading the file will set alarm[0] to 1.
And all of the rest will be into the alarm event.
// Alarm 0 event
global.tool = 1;
ini_open('game.ini');
// and so on

Edited by torigara, 19 June 2012 - 01:04 PM.

  • 0

#7 KevinBlazeCoolerz

KevinBlazeCoolerz

    GMC Member

  • GMC Member
  • 111 posts
  • Version:GM8

Posted 19 June 2012 - 03:18 PM

@torigara: thx for help, but it still not solved my problem :/
i don't know why :blink:
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users