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 / sending an array to a text file

Author
Message
AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 9th Jan 2004 00:32
okay, I've done this many time with qbasic 4.5 -> and liberty basic. But I can't seem to do it with dbasic. I thought it would be just as simple, but I guess not.

I simple want a text file to look like an array, like this:

1,0,0,0,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1
1,0,0,0,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1
1,0,0,0,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1
1,0,0,0,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1
1,0,0,0,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1
1,0,0,0,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1
1,0,0,0,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1

something like that, except 100*100.
Shouldn't putting an array into a text file like that work like this?

open to write 1,"level.map"
for y = 1 to ysize
for x = 1 to xsize
write string 1,str$(map(x,y))
next x
next y
close file 1

but that simply outputs a text file which looks like this
0
0
1
0
1
1
1
0
0
1
etc.

and all the other options (float,word,long,etc.) just give me funny symbols. Isn't there an easy, straight forward way to do this? It's just a simple way to read and write maps.

Thanks.
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 9th Jan 2004 00:45
yeah the way you coded that...it SHOULD look like that.... think about it...you didnt TELL it to put the ','s in.
go through the code one line at a time...

you open the file to write
you make your two loops, x = 1 and y = 1
you write map(1,1) to the first position.
next x, x = 2 and y = 1
you write map(2,1) to the next line
etc...

that is what you are telling it to do.

AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 9th Jan 2004 00:58
yes, but it puts it down the text file and not across.

so instead of the text file looking like this:

0101010001010100011 (no commas)
0101020301771818838
238u714378732899893
7893278932897432878

it looks like this:

0
1
0
1
1
0
1

how can I make it print across, then go down a line?
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 9th Jan 2004 01:08
hrm...not so sure...sorry

Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 9th Jan 2004 04:48
When you use the "Write String" command, the strign is ended in the carrage return symbol. thus, each value is writen to the next line.

To fix it. change it to Write Byte, but don't use the Str$() command, otherwise you will get the weird symbols.

Or, you could keep doing it that way, but you have to modify it a bit, to:



That way, you are adding all of the values of the first dimension to the string temp$ THEN writing it to the file. then temp$ is reset, and the next dimension in the array is writen.

Hope I Helped...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 9th Jan 2004 20:55
open to write 1,"level.map"
for y = 1 to ysize
temp$=""
for x = 1 to xsize
temp$=temp$+str$(map(x,y))
next x
write string 1,temp$
next y
close file 1

should work fine, if you want to write consecutive characters then you need to create the string and the write it, that way you just get one newline at the end of the string and it all comes out as wanted

Mentor.

System spec : Pentium 3.0Ghz, 512MB DDR, 2x160Gb HD (using icewave hd coolers ), DVD RW/CD RW (all modes), multimedia front panel, 6 way surround sound, ATI radeon 9800Pro 128mb.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Jan 2004 04:12
@ Mentor, you just copy and pasted my code didn't you?
lol.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 10th Jan 2004 20:10 Edited at: 10th Jan 2004 20:11
rofl, I just looked at it, thats creepy, even down to the same variable names (well...filched from the original), I read just as far as the bit about about write byte and thought "I wouldn`t do it that way" and promptly ran up the code you see, just pure (twilight zone) coincidence, (btw just what is your current project??? I might have to change mine )

Mentor.

System spec : Pentium 3.0Ghz, 512MB DDR, 2x160Gb HD (using icewave hd coolers ), DVD RW/CD RW (all modes), multimedia front panel, 6 way surround sound, ATI radeon 9800Pro 128mb.
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 10th Jan 2004 22:20
lol

Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 11th Jan 2004 08:17
Lol... When you are asking about "what's your current project", who are you refering to?


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 11th Jan 2004 14:07
@Jessticular: well since we seem to have started writing the same code I thought I might just check if I was wasting my time duplicating your efforts, you aren`t writing a 3D puzzle game based on classic art by any chance are you?

Mentor.

System spec : Pentium 3.0Ghz, 512MB DDR, 2x160Gb HD (using icewave hd coolers ), DVD RW/CD RW (all modes), multimedia front panel, 6 way surround sound, ATI radeon 9800Pro 128mb.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 11th Jan 2004 14:11
Um... No, I can't say that the thought have ever crossed my mind, lol.

I'm currently working on an RTS ( which everyone else seems to be working on too )

Good luck with the Puzzle game though


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy

Login to post a reply

Server time is: 2025-06-06 16:15:42
Your offset time is: 2025-06-06 16:15:42