Saveing a map

Blitz3D Forums/Blitz3D Beginners Area/Saveing a map

Nike(Posted 2009) [#1]
I am making a small game, and it will allow you to make your own map/background. I have a made an editor and it works great, except I can't figure out how to save. I have been looking over my code for weeks without an answer. Here is the saving functions I use.

Function save()


Dim MapArray(11,15) ;array of size 12x16

For x = 0 To 11
	For y = 0 To 15
	
	 If MapArray(x,y) = "1" Then MapArray(x,y) = 1
	 If MapArray(x,y) = "2" Then MapArray(x,y) = 2
	 If MapArray(x,y) = "3" Then MapArray(x,y) = 3
	 If MapArray(x,y) = "4" Then MapArray(x,y) = 4
	 If Maparray(x,y) = 0 Then Maparray(x,y) = 1


	Next

Next

savemap("" + name$ + ".nma")

End

End Function 



Function savemap(filename$)

	Outfile=WriteFile(Filename$)
		If outfile<>0 Then 
			For y=0 To 15
			outstring$=""
				For x=0 To 11
					outstring$ = outstring$ + maparray(x,y)
				Next
			WriteLine outfile,outstring$
			Next
	CloseFile outfile

End Function 



GfK(Posted 2009) [#2]
You have an array of integers, which you're trying parse as if it were an array of strings and convert to integer, then convert BACK to strings in order to save it? Doesn't make a bit of sense.

I don't see where name$ is declared. Given that its in a function, you will need to have declared this as a Global elsewhere, otherwise what you have there is an empty string.

Also in your saveMap function, remove "Then" and put an EndIf after CloseFile.

[edit] Actually, the more I look at that code, the less sense it makes. You're declaring an array in a function. Arrays are always global in BB3D, iirc, but since you're trying to save the data immediately after using Dim(), what you would be saving is an empty array? You haven't populated it with any data.


Nike(Posted 2009) [#3]
Alright, the name$ is declared in the beggining of the code. I also made it global. The If outfile<>0 Then command looked useless after I saw it so its removed. The Dim MapArray(11,15) is at the begging of the code. I made the 11 x and the 15 y and I made x and y global. It is still not working tho. I have never used the dim command before so I am not that good with it.


Warner(Posted 2009) [#4]
In your code above, try calling SaveMap() directly, instead of calling it via Save().
Maybe this code example can help?