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.

Newcomers DBPro Corner / Read from text file..?

Author
Message
aarrowh
16
Years of Service
User Offline
Joined: 19th Oct 2007
Location:
Posted: 24th Feb 2009 02:37
I want to make a text adventure, but I want to make it coordinate based. The coordinates for the world in a text file, and along with each coordinate would be information on what is in each space.

I know how to load a file, but I can't seem to figure out how to get it to read the file for anything specific, much less make it do anything with what it reads.

Any help appreciated,

Aarrowh



Image thanks goes to AndrewT
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 24th Feb 2009 07:41
Well, I suggest using a memblock to organize the data you put into the file. I think memblocks just add a nice structure to things and make it easy to read or write from random parts of the data. Further, you can write the entire memblock to a file and then read it back out with the write memblock and read memblock commands.

In a previous post, I explained all about writing to and reading from memblocks here.

When using memblocks, or any other method to store data, you need to decide on a structure that you want to use. For this case, I might use something like this:

Each tile in the map will use one byte:
1: The number of the tile in this space. 1 for grass, 2 for tree, 3 for whatever, etc.

Each map will have two header words (two bytes) followed by a bunch of tile bytes:
1-2: Map Width (X Size)
3-4: Map Height (Y Size)
5...(5+X*Y): Tile bytes as described above.

And before all of the maps, you could stick another byte to store the number of maps in the word and then that many words or dwords (4 bytes) to store the byte offsets from the beginning of the file of each individual map.

These are just suggestions that might help decide what kind of file structure you want to use.

Ask if you have any questions.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 25th Feb 2009 00:00
Another method different from what Kira sugguested would be to use the FILE COMMANDS.

Using these commands:
Open To Write/Read- Opens a file for writing or reading.
Close File- Closes a file that you were writing to or reading from. Think of it as putting a book away after you finished it in the reading case, or hitting the save button after you've finished writing something in the writing case.

Write/Read String- Writes a string to/Reads a string from a file.
Write/Read Float- Writes a float value to/Reads a float value from a file
Write/Read Word- Writes a word value to/Reads a word value from a file (I think those are just integers?)
*There are others but they are not listed here.

Keep in mind that you have to know the order that things are written in in your file. For example, if you write a string, a float, then a float again, you will have to read that as string,float,float to get the correct readings.

That's all I have time for for now, hope this helps . I actually started writing this hours ago but had to go somewhere and forgot to post it, so someone may have answered your question already.

Login to post a reply

Server time is: 2024-09-28 02:27:07
Your offset time is: 2024-09-28 02:27:07