Results 1 to 12 of 12

Thread: Save Game

  1. #1

    Thread Starter
    Member insaneman's Avatar
    Join Date
    Oct 2001
    Posts
    63

    Save Game

    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?

  2. #2
    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)
    --------------
    PHyReXiAN
    --------------

  3. #3
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Uh, actually, use Binary, not Random.
    "1 4m 4 1337 #4xz0r!'
    Janus

  4. #4

    Thread Starter
    Member insaneman's Avatar
    Join Date
    Oct 2001
    Posts
    63
    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?

  5. #5

    Thread Starter
    Member insaneman's Avatar
    Join Date
    Oct 2001
    Posts
    63
    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.

  6. #6
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Binary and Random both let you use Get/Put, but Get/Put work better in binary mode.
    "1 4m 4 1337 #4xz0r!'
    Janus

  7. #7
    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.
    Last edited by PHyReXiAN; Jun 4th, 2002 at 05:12 PM.
    --------------
    PHyReXiAN
    --------------

  8. #8
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    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.
    "1 4m 4 1337 #4xz0r!'
    Janus

  9. #9

    Thread Starter
    Member insaneman's Avatar
    Join Date
    Oct 2001
    Posts
    63
    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:

    VB Code:
    1. Private Sub Load_Click()
    2. Open "SAVE.sav" For Binary As #1
    3. Get #1, 1, txttext
    4. Close #1
    5.  
    6. End Sub
    7.  
    8. Private Sub Save_Click()
    9.  
    10. Open "SAVE.sav" For Binary As #1
    11. Put #1, 1, txttext
    12. Close #1
    13.  
    14. End Sub

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

  10. #10

    Thread Starter
    Member insaneman's Avatar
    Join Date
    Oct 2001
    Posts
    63
    whoa, major typo there, its suposed to be excactly.

    PS: English int my first language either

  11. #11

    I don't understand

    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 ?)
    --------------
    PHyReXiAN
    --------------

  12. #12

    Thread Starter
    Member insaneman's Avatar
    Join Date
    Oct 2001
    Posts
    63
    oh, that works fine, thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width