Author Topic: Making GM remember a variable  (Read 1937 times)

RandomFangamer

  • Cherry Eater
  • Posts: 71
  • Pico Pico Piiiiiii
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Mozilla compatible Mozilla compatible
    • View Profile
  • Playstyle: Keyboard
Making GM remember a variable
« on: June 22, 2015, 08:25:24 PM »
Hi,   :denKamilia:
So I have just finished making my first boss and when it is killed I have it set a variable (trollkilled) to true
However, when I press r it resets trollkilled to whatever it was originally :denRin:
I am wondering, is there a way to make a variable not reset when the game closes or I press R?
I am guessing that there is some way to store it in the save, but I don't know how.

Code:
(click to show/hide)

Thanks for reading this




:ItsBoshyTime: o o o o o :denProgress: o o o o o :paraKid:

YoSniper

  • Awexome
  • Global Moderator
  • Spike Dodger
  • Posts: 142
  • People regard me as a programming overlord.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
    • My YouTube
  • Playstyle: Keyboard
Re: Making GM remember a variable
« Reply #1 on: June 22, 2015, 08:37:57 PM »
The only way to get the game to permanently remember a variable like that is to put that variable in a persistent object like world.

However, even then, the variable will reset if you restart the game (or shut it down and start it back up.) So for an even more permanent solution, include that variable in your save data (again, remember to save it within the world object.)
I don't traverse the forums as much anymore. Follow me on Twitter if you want to keep tabs on me!

Twitter: @YoSniperGames
Twitch: yosniper

Streams happen whenever I feel like it.

RandomFangamer

  • Cherry Eater
  • Posts: 71
  • Pico Pico Piiiiiii
  • OS:
  • Windows 8.1/Server 2013 Windows 8.1/Server 2013
  • Browser:
  • Mozilla compatible Mozilla compatible
    • View Profile
  • Playstyle: Keyboard
Re: Making GM remember a variable
« Reply #2 on: June 22, 2015, 09:36:50 PM »
How do you put the variable in world?
I have it so that when the player collides with an object (the warp) the variable gets set to true.




:ItsBoshyTime: o o o o o :denProgress: o o o o o :paraKid:

YoSniper

  • Awexome
  • Global Moderator
  • Spike Dodger
  • Posts: 142
  • People regard me as a programming overlord.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.130 Chrome 43.0.2357.130
    • View Profile
    • My YouTube
  • Playstyle: Keyboard
Re: Making GM remember a variable
« Reply #3 on: June 22, 2015, 10:11:45 PM »
Either set the variable in the world object, or an alternative is to just use a global variable (but it still requires initialization, which is best done in the Create Event of the world object, anyway.)

If the variable starts out as false, and is later set to true upon that collision, say:

Create Event of world
Code: [Select]
myVariable = false;
Collision Event with object
Code: [Select]
world.myVariable = true;
Then you would just need to save "world.myVariable" in your save data.

But please, for the sake of code maintainability, don't name the variable "myVariable".
I don't traverse the forums as much anymore. Follow me on Twitter if you want to keep tabs on me!

Twitter: @YoSniperGames
Twitch: yosniper

Streams happen whenever I feel like it.

pieceofcheese87

  • Global Moderator
  • The Kid
  • Posts: 346
  • Personal Text
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.124 Chrome 43.0.2357.124
    • View Profile
    • Twitch Tv Channel
  • Playstyle: Keyboard
Re: Making GM remember a variable
« Reply #4 on: June 22, 2015, 11:53:59 PM »
The best way is to write it to the savefile.

In the saveGame script, add this at the end of the list of variables, but before file_bin_close(f);

Code: [Select]
file_bin_write_byte(f,global.trollkilled)This will write the variable to your savefile when you hit a savepoint.

Now, assuming you're using the yuuutu engine or similar, you need to edit the saveExe script so that it loads the variable from the savefile when you restart.
Again, after everything but before file_bin_close(f); put this:

Code: [Select]
global.trollkilled = file_bin_read_byte(f);
Now it should save the variable.

oh, and a reminder to set the global variable in your warp collision event, instead of just the warp's variable. (global.trollkilled=true instead of trollkilled=true)
« Last Edit: June 22, 2015, 11:58:00 PM by pieceofcheese87 »
Signature