PDA

Click to See Complete Forum and Search --> : Save Game


insaneman
Jun 3rd, 2002, 11:59 AM
i need to make a save game type of thing where there is a set save point, what it has to save is:
1.What form the player is on
2.What wepon he has equiped (Im making it so that when the player equips a new wepon, it is put into a label, so i only have to save the label caption)
3.The players level (Same as above)
4.The players health (" " ")
5.The party thats with the player (im not sure how im doing that yet)

i also have to make a system for loading a game (when it loads all it does is load the form, and load the captions in, not sure about the players party.) Can anyone help me with these things?

PHyReXiAN
Jun 3rd, 2002, 01:14 PM
You have to use the Random Access to write into the "save file".
Here's an example:

Open "SAVE.sav" For Random As #1 'opens the file
put #1, 1, VarForm 'Just put the name of the activated form
put #1, 2,lblWeapon
put #1, 3,lblLevel
put #1, 4,lblHealth
'....................
Close #1

Then if you want to use the saved game:

Open "SAVE.sav" For Random As #1
get #1, 1, VarForm
get #1, 2,lblWeapon
get #1, 3,lblLevel
get #1, 4,lblHealth
'....................
Close #1

Easy ! isn't it ?
I just didn't understand the 5. (Sorry):confused:

Janus
Jun 3rd, 2002, 06:25 PM
Uh, actually, use Binary, not Random.

insaneman
Jun 3rd, 2002, 11:06 PM
so if i want the user to have a choice of not saving in the same slot, and having like 5 slots to save, would i do the same except say save1.sav?

and how would i save using binary?

insaneman
Jun 3rd, 2002, 11:11 PM
and 5, have you ever played FF or any other rpg game? if you have then im talking about the fighting group you are in, the new characters that join you, and help you through the game, i have to save that also, guess ill let only 6 members go into the party and then the battle engine can check which thez are and substitute them in. Well thanks for tha help.

Janus
Jun 4th, 2002, 12:16 AM
Binary and Random both let you use Get/Put, but Get/Put work better in binary mode.

PHyReXiAN
Jun 4th, 2002, 05:08 PM
If I can make a suggestion:

For this kind of games I prefer the Random Access because level names, weapon names, .... have different length.

If you use Binary Access you have to know the length because binary saves bytes per bytes and not plots per plots.

Does it make sense ?

I hope

PS: my mother language is not english.:D

Janus
Jun 4th, 2002, 06:42 PM
Phyrexian: Random access is only for UDTs. Using it for other data types can have unpredictable results, and you're told specifically not to do so in the docs.

You SHOULD know the length of your data - you're saving it, so you should know. If the length can change, then save it with the data. Just because Random is easy, doesn't mean you should use it - part of coding is learning how to do things the hard, proper way instead of the easy, incorrect way.

insaneman
Jun 5th, 2002, 09:58 AM
i tried making a simple program to see excapctily how it works, its just a text box, and two command buttons, one for loading, and one for saving:


Private Sub Load_Click()
Open "SAVE.sav" For Binary As #1
Get #1, 1, txttext
Close #1

End Sub

Private Sub Save_Click()

Open "SAVE.sav" For Binary As #1
Put #1, 1, txttext
Close #1

End Sub


and it doesnt work, i also tried random, but that didnt work either

insaneman
Jun 5th, 2002, 10:00 AM
whoa, major typo there, its suposed to be excactly.

PS: English int my first language either

PHyReXiAN
Jun 5th, 2002, 01:22 PM
For me this piece of code works perfectly:

Private Sub Command1_Click()
Open "****.sav" For Random As #1
Put 1, 1, Text1.Text
Close #1
End Sub

Private Sub Command2_Click()
Dim str As String
Open "****.sav" For Random As #1
Get 1, 1, str
Close #1
Text1.Text = str
End Sub

And this one too:

Private Sub Command1_Click()
Open "****1.sav" For Binary As #1
Put 1, 1, Text1.Text
Close #1
End Sub

Private Sub Command2_Click()
Const length = 5
Dim str As String * length
Open "****1.sav" For Binary As #1
Get 1, 1, str
Close #1
Text1.Text = str
End Sub

You noticed that you have to specify the length of the string.

In fact choose the type of access you want !

(Is that the conclusion ?)

insaneman
Jun 5th, 2002, 01:32 PM
oh, that works fine, thanks.