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.

2D All the way! / Setup for saving a game or game data

Years of Service
User Offline
Joined: 13th Dec 2002
Posted: 13th Dec 2002 11:10
Ok, I got moving the sprite down, I got collision down and even scrolls. This is mostly what I need to make an alright rpg game. But, I need help. I need anyone that can point me to the right direction for saving in the game. I'm mostly an animator and know very little about programming. I know some since I've messed with it in qbasic and some in C. Anyhow, if anyone has any info on how to make a SAVE point in a game please reply back or email me at Thanks
Van B
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 13th Dec 2002 14:48
It all depends on your data mate.

Saving games is not as scary as people think. Make a list of all the arrays and variables you need to store, and then decide how you'll store them. Real numbers that are less than 255 should be written to the file as bytes, text should be written as a string. I usually just save the lot onto 1 big file using the sequential file commands. Then when you make your loading code, just base it exactly on the save code, only reading the data instead, it'll give you your arrays etc. You'll probably have to set some game variables etc, but it's really isn't a big deal.

One thing, it might be easier and smoother if you save your game at the start, then use this as the start point - I mean loading that save the first time it's played. This will let you setup the start position and items with a lot less hassle. Plus it'll force you to have flawless save/load commands, cos it'll be integral from the start.

I coded the file save/load routines for VSD Tracker in 40 minutes. I'll let you see the routines for that if it'll help.

Shadow Robert
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 13th Dec 2002 17:25
Not sure why this is here... but, you should ask yourself what kind of saving you want to have.
This will allow you to develop a save format based on the exact data required at the point of save and size it is wanted to be.

As your working on a PC which gigabyte (in some cases terrabytes) of space you don't really need to worry about size, unless you want to have the information for an internet based game.

first question you need to ask is, do you want save points or dynamic saving. As in do you want the person to save at a set gamepoint say at the end of a level or whatever point of the game they're upto. Games like Quake3 for example use it simply to keep scores of kills and such rather than any actual player information.

Once you know which kinda of saving you want, you'll then need to figure out what addition data is required...
this is usually determined by the game your developing.

I'll explain this better going through a game that would require alot of information to be saved, Metal Gear Solid.
Now you'd use the File IO commands to achieve the saving of all the information you need.

Firstly what information do we need?
- World
-- Area
-- Events
--- Event
--- Triggered?
-- *People
--- Alive or Dead
--- Position
---- X
---- Y
---- Z
---- Rotation Angle (from loaded 0°)
-- *Items
--- Type
--- Position
---- X
---- Y
---- Z
--- Taken or Not
- Snake
-- Position
--- X
--- Y
--- Z
--- Rotational Angle (from loaded 0°)
-- Health
-- Current Weapon
-- Weapon Status
-- Current Item
-- Item Status
-- *Inventory
--- Item Type
--- Ammount

Now first note i've asterisked(*) some of the information, for those it will be far easier to create Arrays for the information you'll be using however you could quite as easily make a Run-Length Encode for them which would save space if you can only use limited amount of say items.

Once we know what data is required you'll need to figure out what kinda of data you can plant them into. I mean you could use Floats for everything, but is quite inefficient as you kinda have to think about loading times - floats are 16bit real value and although oki they don't take up huge ammounts of processing time, for no reason
(this is also why darkbasic can appear to run faster for others because they optimise the values they're working with)

This should be quite easy to do, simply think about what the max values will be ...
under 255 integer then use a byte
under 65535 interger then use a word
within -2147483648 to 2147483648 interger then use a dword|long
and any real number like 0.0 then use a float|file
strings are open to be used, but really hard to optimise them - so i'd use a string of bytes in each one an ansii value for the letter you want to use.

Now the arrays should be populated and exported prior to actually saving the data you need to ... so this should be done within the function - but remember to undim the arrays to keep things healthy.

once you have everything you need, remember to make a gosub for loading the arrays into memory again ... because if you do them within functions they may not work.
they should be loaded into the file at the end, because you can runtime the rest of the information.

now the advantage from save files over external files that you export from other programs is the headers must be built into the game anyways there is no call to make another one.

Now as you'll notice with the exception of positions and angles there are no other Real numbers required. So we'll have to figure out what actually NEEDS to be over 255.
Always best to work to the smallest possible value, faster loading smaller file created.
Well with the exception of status and amounts (in some cases during the game one and the same thing) everything else should be a byte or info.
I'd keep items and such to a set setup ... like
AK47 - type 1
PPK - type 2
blah blah ... this way you'll know what the numbers mean, and best to compile game arrays to let the game also know unless you write down somewhere what they are and refer whilst finishing off coding.

Once you've got the outlines of how the data needs to be, its time to create the save file using a function.
Creating it is simply a matter of reading the file based on a header you've written down for referance, however loading is another affair entirely and you should make use of the function value export ... as each loop it'll run all the statments when you sequentially create files if you export a value from within a you'll get one value per loop rather than just the last value.


that would read the first 100bytes of a save file and dump into an array.
most of your save and read would be similar to that, not really grand ammounts of code to achieve what you need.

read up more on these within the darkbasic 1.1x help files

Anata aru kowagaru no watashi!
Years of Service
User Offline
Joined: 30th Mar 2003
Posted: 30th Mar 2003 10:47
thanks from gumshoe

When the dark angel come's a knocking, don't be shy, let'm in.
Years of Service
User Offline
Joined: 4th Oct 2002
Posted: 3rd Apr 2003 23:40
I'm doing an editor for making a matrix, I've got a lot of it done but
I need to save an array for the height values, also I want to save the x & y size of the matrix and also the tiles. The other thing is that I want to do the cutting image bit as well, so you would load an image and then get images from it then repaste them as they would need to be for the cut command then you would get/save image of that area, this would then give you the bitmap you need for a matrix.

Login to post a reply

Server time is: 2023-09-28 02:21:59
Your offset time is: 2023-09-28 02:21:59