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.

Author
Message
Pandagamesorg
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location: check your moms room :D
Posted: 27th Feb 2011 01:06
What is the code to make a game save your progress (Auto or manual) and make it so you can load that save later (Even if you close the game or turn off the computer)? Is that even possible with BASIC?

Thanks!
Pandagames.org
Agent
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 27th Feb 2011 04:28
Hi Panda,

Take a look at the following commands in the help file:

OPEN TO READ
OPEN TO WRITE
READ FILE
READ STRING
WRITE FILE
WRITE STRING

The idea is to call a function that saves all the variables and arrays that your game uses to keep track of the game state, then call another function later that loads them back in again.

When you save a game, all you need to do is essentially dump the contents of all the variables and arrays into a file, then pass control straight back to your main loop so the current game can carry on. This is fairly straightforward.

When you want to load the game, you need to run different game state initialisation code. Normally you'd clear arrays and set things to zero or other specific values to prepare the way for a fresh game before you pass control to your main loop to commence play. Instead of running this refresh code that sets everything to a zero game state, you'll set everything back to the state it was in when you saved the game, by loading all of those variables and arrays back in from the file and then passing control to the mainloop as if it were a freshly started game - you're just "starting" from a different point.

Make sense?
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 27th Feb 2011 05:56
Like Agent said.

IanM's Matrix Utility plugin has a neat command:

SAVE ARRAY TO DATAFILE

that lets you save a UDT array. For example, in the Space Trader game I'm fiddling with, I've got a 16x12 grid of sectors that the player can visit. So...



and then saving the array stores the "game state" for all the sectors.

Login to post a reply

Server time is: 2024-11-28 00:22:58
Your offset time is: 2024-11-28 00:22:58