Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Help with read/write files

Author
Message
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 10th Oct 2007 04:43 Edited at: 10th Oct 2007 04:43
Well I'm back from my cave, with another question.

Ive been working hard on my pacman(don't laugh), and have started with many level related things, I have decided a good exercise for me would be for my game to read level files, instead of having them built in. I haven't decided on making a level editor or not, but I'm sure of how I want this file to be set up. I need to be able to store a few different things(Ghosts, walls position and size, player start, dots etc) and they need to be neatly set up like so

command position,size

like,



I know how to write and read files(somewhat) but in a very limited manner, I need to know how to not just detect for a whole word on one line, but a specific part of a line, say a comma , or set of numbers, then another and know what each is for. But that's not all, if you know anything good about handling files please share, I need info!

Thanks in advanced!

Your about to get pwned.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Oct 2007 05:17 Edited at: 10th Oct 2007 05:18
Quote: "I need to know how to not just detect for a whole word on one line, but a specific part of a line, say a comma , or set of numbers, then another and know what each is for"


If you are new to writing data files, don't write multiple items on a line. Instead, write each value on its own line.

As long as your read routines are exactly the same as your write routines (the writing loops are in the same order as the reading loops) you should read the info back in correctly.

If the number of items in a given category can vary, simply write out the value to the file. The reading routine would read in the value and use it in a For..Next loop to read in that many items.

Finally, to start with, use Write String for everything. You can then use Windows Notepad to open the file up and check to see if it contains what it should do.

TDK_Man

Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 10th Oct 2007 05:24
alright, but how do you write multiple things on 1 line?

Your about to get pwned.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 10th Oct 2007 16:20
@fxgamer
well the way memblocks store this kind of data is to have pointers that tell you how long a string of data is, you could do the same kind of thing. I can't remember the commands but here's a pseudo example:

The "5" is telling you how long the first string is. So then you would read the first five characters and get "abcde".
You could make a better version that tells you where the string starts and how long it is.

In programming, nothing exists
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 10th Oct 2007 18:32
does read byte just read one character?

http://jamesmason01.googlepages.com/index.htm
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Oct 2007 22:30
Quote: "alright, but how do you write multiple things on 1 line?"


That's the really easy part. But, it just makes reading it back in more difficult as you have to parse it yourself.

So why would you want to?

TDK_Man

Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 15th Oct 2007 05:54
I guess your right, I'm going to experiment some more and see what I get.

Your about to get pwned.
Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 21st Oct 2007 04:35
Are you trying to create, read, or write to files?
Here's an example of writing tile A to a .map:



how do you make a sig?

Login to post a reply

Server time is: 2025-05-31 21:13:12
Your offset time is: 2025-05-31 21:13:12