I am making a game but I don't how to get the game to save.
Please HELP!!!!.
Help
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:
I suppose all your variables are integer, if a var is long long use mkl$ instead of mki$
And to retrieve
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.
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
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
Once variables are recovered, your game init routine must build everything to the required state.
-
- Veteran
- Posts: 202
- Joined: Mon Aug 30, 2004 6:18 am
- Location: Croatia
- Contact:
Wha?
Why not just:
And:
No need for the MKI$ or CVI (make integer string and convert to integer respectively).
Why not just:
Code: Select all
OPEN "MYFILE.TXT" FOR BINARY AS #1
PUT #1, , var1
PUT #1, , var2
CLOSE #1
Code: Select all
OPEN "MYFILE.TXT" FOR BINARY AS #1
GET #1, , var1
GET #1, , var2
CLOSE #1
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
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