Sweet home of Wituz
Stay in touch
  • Home
  • Tutorials
    • GameMaker >
      • Beginner >
        • Create a maze game with levels
        • Create a very simple hit-the-ball game
        • Load/save your game
        • Physics in GameMaker!
      • Intermediate >
        • Create a tower defense game!
        • Split-screen Multiplayer - GameMaker:Studio Tutorial
        • Save and Load Objects using INI files - GameMaker:Studio Tutorial
        • Smooth Camera in GameMaker Using Views
        • Multitouch on devices
    • Unity >
      • Beginner >
        • Create a marble roller game in Unity
        • Make a burning meteor using particle systems in Unity 5
      • Intermediate >
        • Using Character Controllers in Platform Games (Unity 5)
    • Miscellaneous >
      • Make your own "Twitch-Plays" stream
      • Generate a normal map from just one texture
      • Sort your messy folders
      • Modelling a planet in Blender
    • Video tutorials >
      • Make Playstation 1 games
  • Blog
  • Creations
    • Games
    • Apps
  • Contact

Load and save data

In this tutorial i'll show you how you very simply can load and save data. It's useful for remembering settings, hp, positions and so on.
As an easy example, we're going to make a character save its position when the game ends, and restore the position when the game starts. This will work on all devices GameMaker:Studio can export to.

Our target is the thing you see below. Click it, and you'll be able to move with the arrow keys. Refresh the site, and see that the man saved his position

1. Draw a beautiful sprite

.. or load it :) I don't care
Picture

2. Create an object, and make it move

Give it the sprite you just made, and call it obj_beautiful, or anything else. I'm using the name obj_beautiful in this tutorial
Picture

3. Creating the save/load object

This is the object you'll use to save and load data. Therefore, it needs two events:
1. When the game starts, we need to load obj_beautiful's position
2. When the game ends, we need to save obj_beautiful's position
Picture

4. Making obj_loadsave work

An INI file is a file where you can store two things: numbers (real) and text (string).

When the game ends, we want to:
1. Open an INI file
2. Save obj_beautiful's position to the INI
3. Close the INI file

To do this, I only need to explain one function. It's called ini_write_real(). It uses 3 arguments. 
First argument       = the section (the name of the place to save the data, text string)
Second argument = the key (a subname for the section, text string)
Third argument     = the number to save


Of couse, ini_open() will open target INI file, and ini_close() will close target INI file.
Picture
When the game starts, we want to:
1. Check if target INI file exists, stop the code if it doesn't
2. Open an INI file (if it exists)
3. Load and apply obj_beautiful's position from the INI
4. Close the INI file


Code from game start event:
Picture

5. Make a room

Create a room, and put obj_beautiful and obj_loadsave into it
Picture
Try running the game. Move the character, close the game. Then run the game again, and notice that the character now loads the position.
You've now learned how to load and save data in your game, app or anything else. 

Enjoy ^_^

    Stuck? Write your below problem, i'll help you(I'll check this every day)

Submit

Now
2018-04-17


I'm back!
http://www.wituz.com/blog/im-back​
  • Home
  • Tutorials
    • GameMaker >
      • Beginner >
        • Create a maze game with levels
        • Create a very simple hit-the-ball game
        • Load/save your game
        • Physics in GameMaker!
      • Intermediate >
        • Create a tower defense game!
        • Split-screen Multiplayer - GameMaker:Studio Tutorial
        • Save and Load Objects using INI files - GameMaker:Studio Tutorial
        • Smooth Camera in GameMaker Using Views
        • Multitouch on devices
    • Unity >
      • Beginner >
        • Create a marble roller game in Unity
        • Make a burning meteor using particle systems in Unity 5
      • Intermediate >
        • Using Character Controllers in Platform Games (Unity 5)
    • Miscellaneous >
      • Make your own "Twitch-Plays" stream
      • Generate a normal map from just one texture
      • Sort your messy folders
      • Modelling a planet in Blender
    • Video tutorials >
      • Make Playstation 1 games
  • Blog
  • Creations
    • Games
    • Apps
  • Contact