Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Saving/Loading in-game progress

Author
Message
FishCube
12
Years of Service
User Offline
Joined: 31st Jul 2013
Location:
Posted: 31st Jul 2013 01:34 Edited at: 2nd Aug 2013 19:24
I have been working on an rpg for a few weeks, and it is coming along, but i have gotten to the point that i can no longer play it all through, just to get to the latest input. i also want to be able to allow the player to save there game and load it back up in the main menu. i am new to programming so try to explain, if you want to check out my game you can here: http://landsofmagic.webs.com I really want there to be only one save slot so any time you press load game in the menu, you are then able to go back to where you where.

-FishCube-
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 31st Jul 2013 06:01 Edited at: 31st Jul 2013 06:01
exact methods will vary depending on the game ( how it works, how it handles data, gameplay and world design etc) but in the most basic and general terms, to save a game you need to store the current state of any variable that needs to persist and needs to be loaded back later. these are usually written to a file or a database. to load a game, you retrieve this data and set each of those variables back to the saved states/values.

a good place to start will be the file read and write commands. f1 in the eitor will get you to the help index and a listing of file commands

Shazam!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 31st Jul 2013 15:29 Edited at: 31st Jul 2013 15:31
Just as Ortu says.

Here's a small example:



TheComet

FishCube
12
Years of Service
User Offline
Joined: 31st Jul 2013
Location:
Posted: 31st Jul 2013 21:58
Okay so save a variable, but how do i make it so that it goes back to a certain point in the code?

-FishCube-
FishCube
12
Years of Service
User Offline
Joined: 31st Jul 2013
Location:
Posted: 1st Aug 2013 01:49
ok, well how do i make it so that it goes back to a ceratin point in the code?

-FishCube-
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 1st Aug 2013 16:57 Edited at: 1st Aug 2013 17:02
well you cant, exactly. it will start from the start each time it is run, but what you can do is save a level or stage flag (for example, you can set as many and as detailed as you want to narrow down the resume state) which the code can use to decide at what point in the execution it should actuall start doing stuff, if that makes sense.

say your game has levels like mario, you save out the level number, then when you load the game will look at this number and can know what media to load, you save out positions of character and monsters etc and on load place everything back where it was, now you are ready to resume playing.

lets say as an rpg, if you load a game to level 2, execution knows it can skip over the char creation part of the code, based on the level being > 0

Shazam!
FishCube
12
Years of Service
User Offline
Joined: 31st Jul 2013
Location:
Posted: 1st Aug 2013 17:53
How do i set a stage flag? because that makes sense, and it would make it easier if i could use the goto command like in batch, but i cant fugure out the goto command, oh, and im also gonna make it so you can only save the game from the world map, so that every time it loads, the game goes back to the world map loop. but i dont know how to skip over my char creation part

-FishCube-
Nabz_32x
17
Years of Service
User Offline
Joined: 25th Oct 2008
Location:
Posted: 2nd Aug 2013 00:06
a simple variable that checks if a new game is selected
will help you skipping your character selection Screen, just make displaying the whole selection Screen and selection process dependant on this variable.

If you can only save your game on the world map, it would be sufficient to store the characters coordinates on the world map and of course his inventory, stats and key variables which control the Story Progress somehow ( just a guess, as I don“t know how your game will turn out in the end).

Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 2nd Aug 2013 02:00
this is highly simplified but should give you a starting point. gamestate$ is just a basic string variable.



Shazam!
FishCube
12
Years of Service
User Offline
Joined: 31st Jul 2013
Location:
Posted: 2nd Aug 2013 19:22
So what if, i put char creation in an if statement, checking to see if a variable = 1, if it does, skip the if statement and load a game, if it equals 0, start char creation, and when they select load game in the menu, it would set the variable to 1, and engage a load game function. would this work?

-FishCube-
FishCube
12
Years of Service
User Offline
Joined: 31st Jul 2013
Location:
Posted: 3rd Aug 2013 07:22
so i have been able to use your code to make my game ortu, but now do i just do the same thing if i want to store arrays in the .dat file, or is the process different?

-FishCube-
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 3rd Aug 2013 18:43
saving arrays to .dat is pretty much the same, you save and load it by name rather than say a line at a time with strings

Shazam!

Login to post a reply

Server time is: 2026-07-11 06:04:50
Your offset time is: 2026-07-11 06:04:50