Datafile write troubl
Author |
Message |
jrblast
|
Posted: Tue Feb 07, 2006 5:24 pm Post subject: Datafile write troubl |
|
|
For my block breaker game which I'm making I also want to make a level maker (I have it so that it reads the level from a datafile) but when I write the level, lots of extra spaces show up and the new line char shows up as a square...not a new line... heres the code, is there anything wrong? is it a bug? or what....
code: | var lineBreak : string := chr (10)
var clr : string %variable for colour
open : streamIn, (file + ".txt"), write, seek
seek : streamIn, 0
for y : 1 .. rows
for x : 1 .. cols
if blockColour (x,y) <= 0 then
clr := "0"
else
clr := intstr (blockColour (x,y)) (1..1)
end if
write : streamIn, clr
locate (16,1)
put clr, " " , x, " ", y
View.Update
loop
mousewhere (mouseX, mouseY, button)
exit when button > 0
end loop
delay (100)
end for
write : streamIn, lineBreak
end for
close : streamIn |
I'll attatch an example of a file it created...a 30 KB text file o.O(Oh, and the blockColour variable is a 2-D array). The good news is its not as bad as my little mistake yesterday...where i CREATED 19, 500 text files. LMAO
Description: |
|
 Download |
Filename: |
2.txt |
Filesize: |
29.25 KB |
Downloaded: |
75 Time(s) |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Cervantes

|
Posted: Tue Feb 07, 2006 6:08 pm Post subject: (No subject) |
|
|
Try it with put instead of write.
Also, there's no point in seeking to the beginning. When you open a file without giving it mod ability, it clears the file and begins writing from the beginning.
|
|
|
|
|
 |
MysticVegeta

|
Posted: Tue Feb 07, 2006 6:37 pm Post subject: (No subject) |
|
|
I think read and write are more for files with nontext extension...? perhaps. not sure though.
|
|
|
|
|
 |
jrblast
|
Posted: Tue Feb 07, 2006 10:33 pm Post subject: (No subject) |
|
|
Cervantes wrote: Try it with put instead of write.
Also, there's no point in seeking to the beginning. When you open a file without giving it mod ability, it clears the file and begins writing from the beginning.
Okay, that seems to have worked. Thanks
@MysticVegeta: Hmmm...That makes sense I guess.
|
|
|
|
|
 |
codemage

|
Posted: Wed Feb 08, 2006 8:50 am Post subject: (No subject) |
|
|
Put & get make raw text style output.
That makes error checking / debugging your output much, much simpler.
|
|
|
|
|
 |
Cervantes

|
Posted: Wed Feb 08, 2006 5:31 pm Post subject: (No subject) |
|
|
MysticVegeta wrote: I think read and write are more for files with nontext extension...? perhaps. not sure though.
You can give a file any extension you want. It doesn't change the contents of the file. However, using read and write will not produce readable output, as they are for random access, and work in a binary format, rather than standard ASCII.
|
|
|
|
|
 |
|
|