Saving an array of types

BlitzMax Forums/BlitzMax Beginners Area/Saving an array of types

Rico(Posted 2011) [#1]
I want to store the tiled map in my game as multi-dimensional array of types. I want to save it as a file on my harddisk. What is the best way of doing this?

for example

global map:tile[100,100]

type tile
    field data1:int
    field data2:int
    field data3:int
....
endtype



thank you


shinkiro1(Posted 2011) [#2]
Local stream:TStream = WriteStream("yourfile.txt")
Local i:Int
Local j:Int
For i = 0 Until 100
  For j = 0 Until 100
    WriteInt( stream, map[i,j].data1 )
    WriteInt( stream, map[i,j].data2 )
    WriteInt( stream, map[i,j].data3 )
  Next
Next
CloseStream( stream )


Not tested but should work.

EDIT:
-----------------
For restoring your type, you would run the above loop again but instead use the ReadInt command to get the data.
Look in BMax Help -> Modules -> Streams -> BRL.Stream
Last edited 2011

Last edited 2011


Rico(Posted 2011) [#3]
thanks very much Shinkiro :D