Reading and writing map data?

BlitzMax Forums/BlitzMax Beginners Area/Reading and writing map data?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I have a function that reads and writes the map data for my game. The map array "map:int[mapx,mapy]" is filled with random number from 0 to 15.

What is the best way to save the data so that its readable and also what is the best way to read the data back in to the program so that it fills my map array?

This is my current code. Example code would be better for me as I can learn from it better.

To explain more, say for instance I had a tilemap editor which I do :). And when someone makes a level they want to save it to file or load it back in once they have saved it. How can this be done? Can Someone also choose the filname for the saved map? Can someone choose where to save the mapfile?

I know its a lot of question but I'm kindof stuck. I have no clue as to how to do this. I dont get the BlitzMax examples in the docs.

Thanks :)
Function saveload_map()

If KeyHit(KEY_F2)

	If FileType("map.txt") = 0 Then 
 		Local new_map_file = CreateFile("map.txt")
	End If


	Local write_map_file = WriteFile("map.txt")
	For Local x:Int = 0 To mapx-1
		For Local y:Int = 0 To mapy-1
			WriteInt(write_map_file,map[x,y])
		Next
	Next
	CloseStream(write_map_file)

EndIf

If KeyHit(KEY_F1)
	
	Local x:Int = 0
	Local y:Int = 0
	
	Local read_map = ReadFile("map.txt")
	While Not Eof(read_map)
		map[x,y] = Readint(read_map)
		
			x:+1
			y:+1
			
			If x > 5 Then Exit
			If y > 5 Then Exit	
	Wend
	
	CloseStream(read_map)
	
EndIf


End Function