I'm developing my 1st board-game (go-game) in C with Allegro 5, for a course project. Part of my goal is to make a gamesave of the current gamestate. Let's say for 2 players if we exit the game, and log in the game, we want to reload the previous gamestate such that the position of the stones by 2 players to be preserved in their positions. How can I achieve this? I will appreciate any related reference, tutorial, or a git reference I can learn more about saving the states of the game.

P.S. I checked the old questions about saving game state, but there are guides only for other languages/libraries not in C/Allegro.

  • 1
    \$\begingroup\$ What exactly is the part you are stuck on and can't figure out how to perform from Allegro in the questions you've already found here? \$\endgroup\$ – Tyyppi_77 Jan 20 at 13:41
  • \$\begingroup\$ I don't understand what exactly "state" means in game dev? and how it should be implemented? \$\endgroup\$ – SarA Jan 20 at 15:03
  • \$\begingroup\$ Since I am 1st-year BSc in CS, I dont have enough background in CS. My question was I don't understand what exactly "state" means ? I was trying to read gamedevelopment.tutsplus.com/articles/… but looks very complicated for me. I will appreciate if someone could explain it in a simple word with an example. \$\endgroup\$ – SarA Jan 20 at 15:14
  • \$\begingroup\$ "State" is just whatever information describes the current situation in your program. For instance, if the player just started level 5 and has 100 points, the game's state could be described as "level = 5, points = 100". It sounds like in your game, your state is the position of the ball. How have you tried saving and loading that position information to a file so far? \$\endgroup\$ – DMGregory Jan 20 at 15:19
  • 1
    \$\begingroup\$ Despite the title, gamedev.stackexchange.com/questions/25963/… contains good, language-agnostic answers. Unfortunate because save games is a language-agnostic problem. \$\endgroup\$ – congusbongus Jan 20 at 22:55

First, decide what information of your game describes a "game state". In other words, what is the difference between a "new game" and what state the user currently is?

Examples of that are:

  • Character's stats (Name, level, experience, strength, intelligence, money, etc)
  • Quests (What quests have the user completed? What progress do they have on active ones?)
  • Maps (Has the player visited a place before? Do they have fog of war that is explored next time they visit it? After the user has killed enemies on one stage, do they respawn or remain permanently dead?)

Once you have all this information down, it's time to write a file that includes all that information, which is going to be saved on the disc, so it remains there until someone removes it manually. You can pick a simple format like var=value and save all data like this:


quest_kill_dragon=0 # assuming -1 is not started, 0+ started and current state

map_mountain_explored=0 # maybe if you go to a map for the first time a cinematic plays
map_mountain_enemy_2=-1 # -1 on enemy is that they are dead and won't respawn

Please note I used # to display comments, but normally you wouldn't need comments as this file is not meant to be readable by humans. What data you want to save is up to you and what game you are making.

Alternatively you can use JSON to save data on a file, there are plenty of libraries online that help you do that. Unfortunately I haven't used any in the past, so I can't recommend any.

In case its needed, the manual of how to open/close files in C: GNU - Opening and Closing Files

  • \$\begingroup\$ Thanks for the answer. I am afraid that I did not follow exactly what to do. Let me be more concrete: I am building a board-game called "go" with 2 players; In this game, "state" would mean: 1- the location of stones (black and white), and also 2- the points of player has got so far. Could you please clarify your response based on this scenario? Thanks, and apologize! \$\endgroup\$ – SarA Jan 22 at 19:04
  • \$\begingroup\$ @SarA if that detail is important to an answer, make sure it's in your question. Most of us aren't mind readers. ;) Also, make sure you explain how you've tried saving this information so far, and where you got stuck. eg. did you try writing out each players' points the same way TomTsagk shows writing out a character_level into a file in the example above? \$\endgroup\$ – DMGregory Jan 22 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.