Failed loading maps when more than 10?

BlitzMax Forums/BlitzMax Beginners Area/Failed loading maps when more than 10?

Hi! I have run in to a very bad bug with my map loading. Basically when I save maps they save ok and load ok but when there are more than 10 maps loaded it loads all the maps above 10 but not the ones between 1 and 9.

I hope that makes sense.

Here's my map loading Type.

Type TFile
	Field x:Float
	Field y:Float
	Field MapName:String
	Field Fid:Int
	
	Global Maps:String
	Global Files:String[]
	Global TempY:Int = 100
	Global TempX:Int = (800 / 2) - 80
	Global TempYReset:Int = 0
	Global TempID:Int = 0
	Global Page:Int = 0
	Global PageCount:Int = 0
	Global DoLoadMap:Int = 0
	Global DoneLoadingMaps:Int = 0
	Global FList:TList
	
	Global TargetAmount:Int = 19
	
	Function CreateBlankFile() 
		Local array:Int[FMWIDTH, FMHeight]
		Local file:String
		Local FileStream:TStream
			
		For Local x:Int = 0 Until FMWIDTH
			For Local y:Int = 0 Until FMHeight
				Array[x, y]= - 1
			Next
		Next
		
		file = CreateFile("usermaps/blank.map") 
		FileStream = WriteFile("usermaps/blank.map") 
		For Local y:Int = 0 Until FMHeight
			For Local x:Int = 0 Until FMHeight
				WriteInt FileStream, array[x, y]
			Next
		Next
		CloseFile FileStream
	End Function
	
	Function LoadMap() 
		If TFile.DoneLoadingMaps = 0
		    TFile.FList = CreateList() 
			TFile.files = LoadDir("usermaps") 
			For TFile.Maps = EachIn TFile.Files
				Local f:TFile = New TFile
				f.MapName = TFile.Maps
				f.x = 320 'TFile.TempX
				f.y = TFile.TempY
				f.Fid = TFile.TempID
				TFile.TempY:+15
				TFile.TempID:+1
				If TFile.TempID >= 21 and TFile.TempID <= 40
					If TFile.TempYReset = 0
						TFile.TempY = 100
						TFile.TempYReset = 1
					End If
					TFile.Page = 1
				ElseIf TFile.TempID >= 41 And TFile.TempID <= 60
					If TFile.TempYReset = 1
						TFile.TempY = 100
						TFile.TempYReset = 2
					End If
					TFile.Page = 2
				ElseIf TFile.TempID >= 61 And TFile.TempID <= 80
					If TFile.TempYReset = 2
						TFile.TempY = 100
						TFile.TempYReset = 3
					End If					
					TFile.Page = 3
				ElseIf TFile.TempID >= 81 And TFile.TempID <= 100
					If TFile.TempYReset = 3
						TFile.TempY = 100
						TFile.TempYReset = 4
					End If
					TFile.Page = 4
				ElseIf TFile.TempID >= 101 And TFile.TempID <= 120
					If TFile.TempYReset = 4
						TFile.TempY = 100
						TFile.TempYReset = 5
					End If
					TFile.Page = 5
				ElseIf TFile.TempID >= 121 And TFile.TempID <= 140
					If TFile.TempYReset = 5
						TFile.TempY = 100
						TFile.TempYReset = 6
					End If
					TFile.Page = 6
				ElseIf TFile.TempID >= 141 And TFile.TempID <= 160
					If TFile.TempYReset = 6
						TFile.TempY = 100
						TFile.TempYReset = 7
					End If
					TFile.Page = 7
				ElseIf TFile.TempID >= 161 And TFile.TempID <= 180
					If TFile.TempYReset = 7
						TFile.TempY = 100
						TFile.TempYReset = 8
					End If
					TFile.Page = 8
				ElseIf TFile.TempID >= 181 And TFile.TempID <= 200
					If TFile.TempYReset = 8
						TFile.TempY = 100
						TFile.TempYReset = 9
					End If
					TFile.Page = 9
				EndIf
				TFile.FList.AddFirst(f) 
			Next
			TFile.DoneLoadingMaps = 1
		EndIf
	End Function

	Method DrawMapName() 
		If TFile.PageCount = 0
			If Fid >= 0 And Fid <= 20
				DrawText "Map " + Fid + " = " + MapName, x, y
			EndIf
		ElseIf TFile.PageCount = 1
			If fid >= 21 And fid <= 40
				DrawText "Map " + Fid + " = " + MapName, x, y
			End If
		ElseIf TFile.PageCount = 2
			If fid >= 41 And fid <= 60
				DrawText "Map " + Fid + " = " + MapName, x, y
			End If
		ElseIf TFile.PageCount = 3
			If fid >= 61 And fid <= 80
				DrawText "Map " + Fid + " = " + MapName, x, y
			End If
		ElseIf TFile.PageCount = 4
			If fid >= 81 And fid <= 100
				DrawText "Map " + Fid + " = " + MapName, x, y
			End If
		ElseIf TFile.PageCount = 5
			If fid >= 101 And fid <= 120
				DrawText "Map " + Fid + " = " + MapName, x, y
			End If
		ElseIf TFile.PageCount = 6
			If fid >= 121 And fid <= 140
				DrawText "Map " + Fid + " = " + MapName, x, y
			End If
		ElseIf TFile.PageCount = 7
			If fid >= 141 And fid <= 160
				DrawText "Map " + Fid + " = " + MapName, x, y
			End If
		ElseIf TFile.PageCount = 8
			If fid >= 161 And fid <= 180
				DrawText "Map " + Fid + " = " + MapName, x, y
			End If
		ElseIf TFile.PageCount = 9
			If fid >= 181 And fid <= 200
				DrawText "Map " + Fid + " = " + MapName, x, y
			End If
		EndIf
	End Method
	
	Function ShiftLoadText() 
		If KeyHit(KEY_LEFT) 
			If TFile.PageCount = TFile.Page + 1
				TFile.PageCount = TFile.Page
			End If
			TFile.PageCount:-1
			If TFile.PageCount <= 0 Then TFile.PageCount = 0
		ElseIf KeyHit(KEY_RIGHT) 
			If TFile.PageCount = -1
				TFile.PageCount = 0
			End If
			If TFile.PageCount >= 0
				TFile.PageCount:+1
			EndIf
			If TFile.PageCount > TFile.Page
				TFile.PageCount:-1
			EndIf
		End If
		DrawText "" + TFile.PageCount, 0, 0
	End Function
	
	Function SelectMap() 
		If TFile.DoneLoadingMaps = 1
			Local Line:String
			Local MapIdSelected:Int = 0
			Local LoadTheMap:Int = 0
			
			Local f2:TStream
			Local File:String
			Local f:String
			
			Repeat
				Cls
				
				DrawImage imgLoadMapBKG, 0, 0, 0
				
				For Local f:TFile = EachIn TFile.FList
					f.DrawMapName
				Next
				
				If KeyHit(KEY_ESCAPE) 
					MapIdSelected = 0
					TFile.DoLoadMap = 0
					For Local f:TFile = EachIn TFile.FList
						f.Fid = 0
					Next
					TFile.FList = Null
					TFile.TempID = 0
					TFile.TempY = 100
					TFile.TempX = (800 / 2) - 80
					TFile.Page = 0
					TFile.PageCount = 0
					TFile.TempYReset = 0
					TFile.DoneLoadingMaps = 0
					Exit
				End If
				
				TFile.ShiftLoadText
				
				Local InfoText:String = " Enter Map Number To Load Below"
				DrawText InfoText, 280, 515
				Local OutputText:String = "Map Number? : " + Line$
				DrawText OutputText, 300, 535
				If MilliSecs() mod 800 < 400 Then DrawRect(300 + TextWidth(OutputText), 535, 2, TextHeight("|")) 
				Flip
				Local char:Int = GetChar() 
				If char<>0 Then
					
					Select True
						Case char >= 32
							Line$ :+ Chr(char)
							
						Case char = 8 ' backspace
							Line$ = Line$[..Line$.length - 1]
							
						Case (char = 27) ' or (char = 13)  ' escape and enter
							Line$ = Null
							
						Case (char = 13) 
							If Line$ <= TFile.TempID - 1 and Line$ >= 0
								MapIdselected = 1
								Exit
							Else
								MapIdSelected = 0
								TFile.DoLoadMap = 0
								For Local f:TFile = EachIn TFile.FList
									f.Fid = 0
								Next
								TFile.FList = Null
								TFile.TempID = 0
								TFile.TempY = 100
								TFile.TempX = (800 / 2) - 80
								TFile.Page = 0
								TFile.PageCount = 0
								TFile.TempYReset = 0
								TFile.DoneLoadingMaps = 0
								Exit
							EndIf
							
					End Select
				EndIf
			Forever
									
			If MapIdSelected = 1
			
				For Local f:TFile = EachIn TFile.FList
				
					If Line$ = f.Fid
					
						File = f.MapName
						f2 = ReadFile("usermaps/" + File) 
						 	Local TeleportTotal:Int
							Local EnemyTotal:Int
							For Local y:Int = 0 Until FMHeight
								For Local x:Int = 0 Until FMWIDTH
									FactoryMap[x, y].id = ReadInt(f2) 
									If FactoryMap[x, y].id = 20
										TTile2.MaxDax = 1 
									End If
									If FactoryMap[x, y].id = 11
										TeleportTotal:+1
										Print TeleportTotal
									EndIf
									If NumTeleports = 3 Or NumTeleports = 2
										If TeleportTotal = 0
											NumTeleports = 0
										EndIf
			
										If TeleportTotal = 1
											NumTeleports = 1
										End If
									EndIf
									
									If NumTeleports = 0
										If TeleportTotal = 0
											NumTeleports = 0
										End If
										If TeleportTotal = 1
											NumTeleports = 1
										End If
										If TeleportTotal = 2
											NumTeleports = 3
										End If
									End If
									
									If NumTeleports = 1
										If TeleportTotal = 0
											NumTeleports = 0
										End If
										If TeleportTotal = 1
											NumTeleports = 1
										End If
										If TeleportTotal = 2
											NumTeleports = 3
										End If
									End If
									
									If FactoryMap[x, y].id = 21
										EnemyTotal:+1
									End If
									
									If TTile2.MaxEnemy = 6 Or TTile2.MaxEnemy = 5
										If EnemyTotal = 5
											TTile2.MaxEnemy = 6
										End If
										If EnemyTotal = 4
											TTile2.MaxEnemy = 4
										EndIf
										If EnemyTotal = 3
											TTile2.MaxEnemy = 3
										End If
										If EnemyTotal = 2
											TTile2.MaxEnemy = 2
										End If
										If EnemyTotal = 1
											TTile2.MaxEnemy = 1
										End If
										If EnemyTotal = 0
											TTile2.MaxEnemy = 0
										End If
									End If
									
									If TTile2.MaxEnemy = 4
										If EnemyTotal = 5
											TTile2.MaxEnemy = 6
										End If
										If EnemyTotal = 4
											TTile2.MaxEnemy = 4
										EndIf
										If EnemyTotal = 3
											TTile2.MaxEnemy = 3
										End If
										If EnemyTotal = 2
											TTile2.MaxEnemy = 2
										End If
										If EnemyTotal = 1
											TTile2.MaxEnemy = 1
										End If
										If EnemyTotal = 0
											TTile2.MaxEnemy = 0
										End If
									End If									

									If TTile2.MaxEnemy = 3
										If EnemyTotal = 5
											TTile2.MaxEnemy = 6
										End If
										If EnemyTotal = 4
											TTile2.MaxEnemy = 4
										EndIf
										If EnemyTotal = 3
											TTile2.MaxEnemy = 3
										End If
										If EnemyTotal = 2
											TTile2.MaxEnemy = 2
										End If
										If EnemyTotal = 1
											TTile2.MaxEnemy = 1
										End If
										If EnemyTotal = 0
											TTile2.MaxEnemy = 0
										End If
									End If	

									If TTile2.MaxEnemy = 2
										If EnemyTotal = 5
											TTile2.MaxEnemy = 6
										End If
										If EnemyTotal = 4
											TTile2.MaxEnemy = 4
										EndIf
										If EnemyTotal = 3
											TTile2.MaxEnemy = 3
										End If
										If EnemyTotal = 2
											TTile2.MaxEnemy = 2
										End If
										If EnemyTotal = 1
											TTile2.MaxEnemy = 1
										End If
										If EnemyTotal = 0
											TTile2.MaxEnemy = 0
										End If
									End If	

									If TTile2.MaxEnemy = 1
										If EnemyTotal = 5
											TTile2.MaxEnemy = 6
										End If
										If EnemyTotal = 4
											TTile2.MaxEnemy = 4
										EndIf
										If EnemyTotal = 3
											TTile2.MaxEnemy = 3
										End If
										If EnemyTotal = 2
											TTile2.MaxEnemy = 2
										End If
										If EnemyTotal = 1
											TTile2.MaxEnemy = 1
										End If
										If EnemyTotal = 0
											TTile2.MaxEnemy = 0
										End If
									End If										

									If TTile2.MaxEnemy = 0
										If EnemyTotal = 5
											TTile2.MaxEnemy = 6
										End If
										If EnemyTotal = 4
											TTile2.MaxEnemy = 4
										EndIf
										If EnemyTotal = 3
											TTile2.MaxEnemy = 3
										End If
										If EnemyTotal = 2
											TTile2.MaxEnemy = 2
										End If
										If EnemyTotal = 1
											TTile2.MaxEnemy = 1
										End If
										If EnemyTotal = 0
											TTile2.MaxEnemy = 0
										End If
									End If	
																																													
								Next
							Next
					
						MapIdSelected = 1
						TeleportTotal = 0
						EnemyTotal = 0
						Exit
					EndIf
				
				Next
			
				If MapIdSelected = 1
					CloseFile(f2) 
					MapIdSelected = 0
					TFile.DoLoadMap = 0
					For Local f:TFile = EachIn TFile.FList
						f.Fid = 0
					Next
					TFile.FList = Null
					TFile.TempID = 0
					TFile.TempY = 100
					TFile.TempX = (800 / 2) - 80
					TFile.Page = 0
					TFile.PageCount = 0
					TFile.TempYReset = 0
					TFile.DoneLoadingMaps = 0
				EndIf
			End If
		EndIf
	End Function
	
End Type


Can anyone spot why when I save maps and more than 10 are saved the first 10 don't load anymore?

out of curiosity what names are you using for the maps? it is posible that it is not loading them in the order you want.
<edited>
if you are using 0,1,2,3..10,11,12..20,21,22,23. save them like this 001,002,003..010,011,012,013..021,022,023.

The maps are given whatever name the user choses. I assign .FID to each of them on loading them from the directory and when the process is finished I null the list. When I go to load a map again a recreate the list and assign new FID to the loaded maps.

I'll try your suggestion though to see if it makes a difference.

I'm still not understanding why it loads maps 10 and onwards but maps 1 to 9 it doesn't.

:/

[edit] It loads the first map and map number 10 and onwards. The maps are being saved properly because when I remove some maps from the directory and try loading them it loads them perfectly.

There's a rogue variable somewhere causing this, I can feel it. :)

Please if there are any expert bug spotters (Code Bug Spotters that is) can you have alook at the code I posted and see if anything is wrong.

Please!

:)

if you post a link to the executable I think I can fix it for you. I don't need the source just everything else.
or if you prefer email it to me.
The reason I am helping you is because I am interested in building my own platform game. and your ideas will help me tackle some problems I may have in the future. but if you would rather have somebody else help you I won't get offended.

Hey Jesse. I'm going to be sending you the source and the media. Plus in the rar archive I'm sending is the redi.mod which I use to handle the audio for music. You need to put redi.mod in your BlitzMax mod directory.

Thanks for helping out. Gonna email the stuff to you now. :)

Amon, you got mail.

Thanks dude. Just replied. :)