Help

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Guest

Help

Post by Guest »

:( I am making a game but I don't how to get the game to save.
Please HELP!!!!.
Antoni

Post by Antoni »

First you need to identify the variables that carry the state of the game: character positions, items you are carrying, score, level, it depends on the game so it's up to you to find them. You don't need to save everything, find the basic variables, everything else can be calculated from them.
Suppose those variables are var1 to varN

To save:

Code: Select all

open "mysave.dat" as #1 for binary 
put #1,,mki$(var1)
put #1,,mki$(var2)
...
put #1,,mki$(varN)
close #1
I suppose all your variables are integer, if a var is long long use mkl$ instead of mki$

And to retrieve

Code: Select all

i$="xx"
l$="xxxx"
open "mysave.dat" as #1 for binary 
get #1,,i$ : var1=cvi(i$)
get #1,,i$ :var2=cvi(i$)
...
get #1,,i$ :varN=cvi(i$)
close #1
If some vatiable is long use L$ in the place of I$ and cvl instead of cvi

Once variables are recovered, your game init routine must build everything to the required state.
Lachie Dazdarian
Veteran
Posts: 202
Joined: Mon Aug 30, 2004 6:18 am
Location: Croatia
Contact:

Post by Lachie Dazdarian »

Damn you!

I wanna help someone too!

:P
Lachie Dazdarian - The Maker Of Stuff
Guest

Post by Guest »

Wha?

Why not just:

Code: Select all

OPEN "MYFILE.TXT" FOR BINARY AS #1
   PUT #1, , var1
   PUT #1, , var2
CLOSE #1
And:

Code: Select all

OPEN "MYFILE.TXT" FOR BINARY AS #1
   GET #1, , var1
   GET #1, , var2
CLOSE #1
No need for the MKI$ or CVI (make integer string and convert to integer respectively).
Neo Deus Ex Machina

Post by Neo Deus Ex Machina »

Oh sorry, the above post was mine. I forgot to type my username. (*hmn* I really got to register some day ;))
Antoni

Post by Antoni »

You're right, Neo...Where was my mund when i wrote that?
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Binary files tend to be smaller and easier to manage. Much better to use. :D
Anonymous

Post by Anonymous »

Yep :D But there's a choice which programmers have to make.

Using Binary files means: easy and fast reading/writing, but not easy making or editing files yourself without a hex editor or a self-made program.

Using Sequential files mean: easy but slow reading/writing, but it's easy to edit the files yourself, like with notepad.

It's the choice, depending on what the file is going to be used for :)
Post Reply