Basic Real Time

version 2 by Sarah Morayati

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 2 - Save/Restore

    Include (-

    ! This is the SAVE_THE_GAME_R routine from Glulx.16t, with a StartTimer routine injected.
    ! Saving a game saves the states of the global variables too. However, without this
    ! injected routine, the Glulx timer will not restart. This rectifies that. NOTE: If you
    ! are using any other extension that modifies SAVE_THE_GAME_R, there may be conflicts.

    [ SAVE_THE_GAME_R res fref;
        if (actor ~= player) rfalse;
        fref = glk_fileref_create_by_prompt($01, $01, 0);
        if (fref == 0) jump SFailed;
        gg_savestr = glk_stream_open_file(fref, $01, GG_SAVESTR_ROCK);
        glk_fileref_destroy(fref);
        if (gg_savestr == 0) jump SFailed;
        @save gg_savestr res;
        if (res == -1) {
            ! The player actually just typed "restore". We're going to print
            ! GL__M(##Restore,2); the Z-Code Inform library does this correctly
            ! now. But first, we have to recover all the Glk objects; the values
            ! in our global variables are all wrong.
            GGRecoverObjects();
            glk_stream_close(gg_savestr, 0); ! stream_close
            gg_savestr = 0;
            StartTimer(time_total - time_elapsed);
            return GL__M(##Restore, 2);
        }
        glk_stream_close(gg_savestr, 0); ! stream_close
        gg_savestr = 0;
        if (res == 0) return GL__M(##Save, 2);
        .SFailed;
        GL__M(##Save, 1);
    ];


    -) instead of "Save The Game Rule" in "Glulx.i6t".