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 / reading from a text file.....

Author
Message
simonuk74
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location:
Posted: 18th Apr 2003 22:09
is it possible to have a text file like this ( abc.txt ) :
100110110
101100010
100011010
010111011
101111010
110100011

and get DBP to read the file, and figure out wether its just read a 0 or 1 ?, or whatever value it may be

is it also possible for DBP to know when its reached the end of a line, or an empty line ( ie end of file )???
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 18th Apr 2003 22:39
yes, you can write with the '%' binary symbol
8binary booleans to a byte
as you're reading a txt file you'll only need a byte of data (perhaps even only 128, depends what languages really)

when you load you load in bytes of data, common practise used to make sure that the byte loaded is free is to check for a signature bit stream.

for example you read each byte like



you'd then say check so see an end of a line once you've put everything in an array, most people use %1100 0000 as the most common end of line (don't ask me why) but you should try to pick something which you know you won't be using.

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
simonuk74
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location:
Posted: 18th Apr 2003 23:11
thanks very much for the info, I hope it helps me, ( I`ve not ran it yet- so I dont fully how it will work )

what its for is a map editor, where 1 will be a wall, and 0 will be floor space ( ie player can move around on 0 values)
I have coded a simple prog to make the map from an array : map (x,y)
where X&Y are map co-ordinates, which will reurn a value, 0 for wall, 1 for wall, 2 for door, so on..
but I`ll also have a selection of textures, and also different floor types ( water, acid, sand - so on )
All of these will have a different value, so the text file to read may look more like this :

11111111 these would be co-ordiates, 0,0 top left, 7,4 bottm right
10010401
11211211
10902001
11111111

I`m sorry for the last one just looking like binary, it wasnt meant to be really - I coded a map a while ago, ( which I have lost ), and all the map data was held like this, but it was a massive task to create it all.

This is why I`m doing an editor

So what I really meant to ask is, can DBP read the value of a position in the text file , ie co-ordinate 5,1 =4
so then my code would place in the map the respective component, if you see what I mean.


Simon

the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 18th Apr 2003 23:23
http://www.darkbasicpro.com/tutorials.php

Read the huge dungeons tutorial.
simonuk74
23
Years of Service
User Offline
Joined: 3rd Nov 2002
Location:
Posted: 18th Apr 2003 23:46
oops, lol, I forgot I had that, I played with wah the source code produce, but didnt look much further than that, as it was dreadfully slow on my pc., but I have figured a way out of redrawing the map using less objects, as in if a wall is 20 cubes long, I get my code to draw one box, the length of 20 cubes! - so my code will be faster ( on my pc anyway! )
I had done a complete level like this before, in DBC, but I had lost it.
I could create it again, but it was only one level, and I want to make an editor, as it took ages to put the code in for one level.

Simon

Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 19th Apr 2003 04:06
One technique I use is DATA and READ statements. I did a similar thing. I made a map layout of tiles, using a text file like that, then I just copied all the data into my DB source code, and put it all in a set of DATA statements, then just had a routine that ran through it and loaded it all into an array. Easy.

Probably the best way for non-changing data, but it wont work if you want the user to be able to customise the data being loaded. Seems like that might be what you had in mind, but if not, DATA and READ statements are proper gems.

Machine: P4 2200, 1GB RAM, GeForce4 64MB, Audigy Platinum
http://www.kontact-kru.com for my own personal drum'n'bass creations.
Coming soon: http://www.breakbeat-terrorism.co.uk

Login to post a reply

Server time is: 2026-07-10 23:13:41
Your offset time is: 2026-07-10 23:13:41