Game Programming and Development Tools

File Management - BB – Mene-Mene

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
I'm in need of help on file management. I can make, delete, and write to files fine, but I'm having trouble changing files.

Ex.
Lvl. 6 Jedi fights sarlaac and wins. He gains level. I need to store his new level in the appropriate slot, problem is, there is also strings in the file.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

firemaker103

Member

Posts: 643
From:
Registered: 07-13-2005
The easiest way is probably just to write the whole data file over again.

------------------
I would like to change the world, but they wouldn't give me the source code.

[This message has been edited by firemaker103 (edited January 10, 2007).]

samw3

Member

Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
I'm not sure what BB is. But if one of those B's stand for basic then you should have a "seek" command.

Are all your "slots" the same size? If so you could use "seek" to move the file pointer to the record you want to modify.

recPos = seek(playerNum*recSize)

And just write the record over again.

The problem comes with deletion. At some point you will have to garbage collect.

------------------
Sam Washburn

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Thats my problem. I'm not sure if strings are the same size. BB = BlitzBasic. What your talking about I think is SeekFile()

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

samw3

Member

Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
Well, from my experience, you can't insert space into the middle of a file (easily) in code. So, the two options that come to mind are:
1. make the records the same size and pad to a maximum length of the string.
This can wreak major havoc tho if the string happens to go beyond the max len since it will overwrite the start of the next record.

2. rewrite the file each time as firemaker103 suggested

There is another option and that would be to try and implement a file insert function that would insert space. You would also need, then to track the positions of the records at the beginning of the file.(since they would be variable)

For me it would depend upon how many records I was dealing with and the forseen max size of the file. If it was just a few records, like 1-12, and total file size was under say 1MB, I'd just write the file over again.

------------------
Sam Washburn