Storing Game data in seperate files - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Storing Game data in seperate files

BahkranBahkran Posts: 33Member
OK,

I am writing a 3D-isometric turn-based strategy game in VB5 and I am having trouble writing and reading to and from files. When I have one section done I can change it to the rest but I can't get started. The file would compromise of People Data, for each person there are attributes assigned to them:

ID (Integer)
Name (String)
Military Potential (Integer)
Economic Potential (Integer)
Political Potential (Integer)

When the program gets the information, it sends the ID number to the file and I want the attributes assigned with that ID back and into variables. I have messed around with the Get and Put statements but alas; no luck. The data file would also need to be written from a separate file, not available to the end user but so that it is easier to put the 500+ people in.

Any ideas? Please reply here or email me: [email protected] I can’t pay in money for advice but will repay in your problems if necessary.

Thanx,
Bahkran

Comments

  • MachairaMachaira Posts: 13Member
    Create a UDT to store this data, like:

    Type udtPerson
    sName As String
    iMilitaryPotential As Integer
    iEconomicPotential As Integer
    iPoliticalPotential As Integer
    End Type


    Here's code that will save and read the data:

    'Save
    Dim iFileNum As Integer
    Dim iLp As Integer

    iFileNum = FreeFile

    Open "c:files est.dat" For Binary As iFileNum

    Put #iFileNum, , UBound(People)

    For iLp = 0 To UBound(People)
    Put #iFileNum, , People(iLp)
    Next iLp

    Close iFileNum

    'Read
    Dim iFileNum As Integer
    Dim iLp As Integer

    iFileNum = FreeFile

    Open "c:files est.dat" For Binary As iFileNum

    Get #iFileNum, , iNumPeople
    ReDim People(iNumPeople)

    For iLp = 0 To UBound(People)
    Get #iFileNum, , People(iLp)
    Next iLp

    Close iFileNum


    HTH, let me know if there are any problems.

Sign In or Register to comment.