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 Professional Discussion / Writing to text file

Author
Message
Teh Stone
16
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 26th Feb 2011 20:44
Im using the following code to read data for a tile map from .txt file into a 2d array, the data in the file is in the form of



and the numbers are just image numbers, this is proberly real simple but i dont know where to even start on it but how would i go about writing a text file in the same form out of the array if i make changes to it

Hers the code im using for reading

Jeff Miller
21
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 26th Feb 2011 21:36 Edited at: 26th Feb 2011 21:39
If you review the File Commands help file, you will see corresponding Write commands for the Read commands you are using. Your burden in setting up a routine to populate the file is that you will have to positively create the spaces between the string expressions of the values you are storing, and also insuring that low number values (like the double zeroes) are correctly written.

To write a two-character string of a value (that had better not be more than 99) with a trailing space you might try to write Right$(100 + value,2) + " ". That will ensure that a value such as 1 will write as "01" instead of "1", and thereby not throw off your file reading code.

If the double characters in your example are in fact image numbers then I presume you are intercepting the resulting zero value to trigger some result other than loading or getting an image number, since DBP does not accommodate an image number zero.

Before you plunge too deeply into creating text files to store integers, I would recommend looking at ways to store them as integers. In addition to the DBP file commands, IanM has developed data bank commands that allow you to efficiently store and read all data types typically used in DBPro. Check out his Matrix Utilities plug-ins on the DLL forum board. I use them every day.

Login to post a reply

Server time is: 2026-07-16 23:19:26
Your offset time is: 2026-07-16 23:19:26