Page 1 of 1
Help
Posted: Sun Aug 29, 2004 3:00 pm
by Guest

I am making a game but I don't how to get the game to save.
Please HELP!!!!.
Posted: Sun Aug 29, 2004 4:18 pm
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.
Posted: Mon Aug 30, 2004 6:49 am
by Lachie Dazdarian
Damn you!
I wanna help someone too!

Posted: Mon Aug 30, 2004 9:04 am
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).
Posted: Mon Aug 30, 2004 9:52 am
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

)
Posted: Mon Aug 30, 2004 11:46 am
by Antoni
You're right, Neo...Where was my mund when i wrote that?
Posted: Mon Aug 30, 2004 9:10 pm
by Nodtveidt
Binary files tend to be smaller and easier to manage. Much better to use.

Posted: Tue Aug 31, 2004 6:49 am
by Anonymous
Yep

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
