Saving multiple ints on same line?

BlitzMax Forums/BlitzMax Beginners Area/Saving multiple ints on same line?

IKG(Posted 2006) [#1]
I really didn't want to ask this question, but after 30 minutes of trying I might as well just ask and learn.

All I want to do is save four separated integers per line. In other words, how can I write four variables on a single line (separated by commas) to a .txt file? And when I've done that, how can I start a new line underneath the previous one and do that same process over again?

Thanks a bunch! I've always had a tough time with file creation, and the BlitzWiki didn't help me that much.

By the way, why can't numbers be read on a .txt file with Notepad? They're always replaced by symbols.


H&K(Posted 2006) [#2]
why can't numbers be read on a .txt file with Notepad? They're always replaced by symbols


Thats because the ascii char of that int number is a symbol. You are not saveing the number 4, when you send a 4 to the stream. You are sending the ascii symbol 4, (which is a system code I think). So 65 for example wouldnt be 65 (which afterall is two values), but a "A", (agian, not sure would need an ascii table)

You should convert the number to a string, then send the string to the stream, then for a newline, send the ascii value for a new line. (/n I think)

And also for the comma, just send ","


kronholm(Posted 2006) [#3]
myIntVar.toString() might help a bit here


FlameDuck(Posted 2006) [#4]
Something like this?
Local myInts:Int[] = [1,2,3,4,5,6,7,8,9,0]
Local myStream:TStream = WriteStream("numbers.txt")
Local count:Int = 0
For i:Int = EachIn myInts
	mystream.writestring(i)
	count:+1
	If count Mod 4 = 0
		myStream.writestring("~r~n")
	Else
		myStream.writestring(",")
	EndIf		
Next