Game programming

Moderators: None (Apply to moderate this forum)
Number of threads: 2047
Number of posts: 5331

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Storing Game data in seperate files Posted by Bahkran on 20 Jun 2001 at 2:10 AM
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: stephenpcornish@hotmail.com. I can’t pay in money for advice but will repay in your problems if necessary.

Thanx,
Bahkran

Report
Re: Storing Game data in seperate files Posted by Machaira on 29 Jun 2001 at 3:13 PM
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\test.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\test.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.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.