Qbasicnews.com

Full Version: save and load function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how can i make an easy way to make an save and load stuff for my games with the open commnad
Easy way? I don't quite understand you, but I'll try to guess.

The easiest way to save game data is opening a text file with OPEN "file" FOR OUTPUT AS #filenumber, and then putting important variables in it using PRINT #filenumber, variable. Don't forget to CLOSE #filenumber when you're done.

To load, just OPEN "file" FOR INPUT AS #filenumber, and get those variables from the file using INPUT #filenumber, variable. Don't forget to CLOSE #filenumber.

For more info, check QB help and try to be more specific in your next post, just to point me in the direction where I should help you Smile
ok... that just wat i wontd to know
The easiest way is to use get and put, but that advice only applies if you know exactly what you'll be saving and loading. INPUT/OUTPUT is a lot easier to manipulate if you decide to add something later or change the format..
Why dont u create a type containing all the variables and just PUT it in a binary file and then when u require to retrieve it just GET it from the file in the same variable like this:

Type typgame
score as integer
...
...
...
End Type

DIM gm AS typgame

gm.score = 1000
gm.... = ...

'To put
OPEN "game.bin" FOR BINARY AS #1
PUT #1, gm
CLOSE #1

'To get
OPEN "game.bin" FOR BINARY AS #1
GET #1, gm
CLOSE #1

P.S: I am sleepy right now so just take this code as a guide line 8)