GetChar related?
BlitzMax Forums/BlitzMax Beginners Area/GetChar related?
| ||
| I have my tilemap editor loading and saving maps perfectly. The thing is it's only perfect if I pick the correct file. Take a look at this code. This is part of the mapfile loading.
Function SelectMap()
If TFile.DoneLoadingMaps = 1
Local Line$
Local MapIdSelected:Int = 0
Local LoadTheMap:Int = 0
Local f2:TStream
Local File:String
Local f:String
Repeat
Cls
For Local f:TFile = EachIn TFile.FList
f.DrawMapName
Next
If KeyHit(KEY_ESCAPE)
TFile.DoLoadMap = 0
For Local f:TFile = EachIn TFile.FList
f.id = 0
Next
TFile.FList = Null
TFile.TempID = 0
TFile.TempY = 100
TFile.DoneLoadingMaps = 0
Exit
End If
Local OutputText:String = " Enter Map Number to Load : " + Line$
DrawText OutputText, 280, 500
If MilliSecs() mod 800 < 400 Then DrawRect(280 + TextWidth(OutputText), 500, 2, TextHeight("|"))
Flip
Local char:Int = GetChar()
If char<>0 Then
'Print char 'Debug porpouses, check for spetial characters not being displayed in the BM window becouse of a incomplet default font.
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)
MapIdselected = 1
Exit
End Select
EndIf
Forever
If MapIdSelected = 1
'TTile2.MapClearMap
Print "2"
For Local f:TFile = EachIn TFile.FList
Print "3"
If Line$ = f.id
Print "4"
File = f.MapName
f2 = ReadFile("usermaps/" + File)
For Local y:Int = 0 Until FMHeight
For Local x:Int = 0 Until FMWIDTH
FactoryMap[x, y].id = Readint(f2)
Next
Next
Print "Yay - Loaded"
Else
End
EndIf
Next
If MapIdSelected = 1
CloseFile(f2)
MapIdSelected = 0
TFile.DoLoadMap = 0
For Local f:TFile = EachIn TFile.FList
f.id = 0
Next
TFile.FList = Null
TFile.TempID = 0
TFile.TempY = 100
TFile.DoneLoadingMaps = 0
EndIf
End If
EndIf
End Function
End Type
I store the maps in a type and assign an ID "number from 0 and above". The offending bit of code is here.
If MapIdSelected = 1
'TTile2.MapClearMap
Print "2"
For Local f:TFile = EachIn TFile.FList
Print "3"
If Line$ = f.id
Print "4"
File = f.MapName
f2 = ReadFile("usermaps/" + File)
For Local y:Int = 0 Until FMHeight
For Local x:Int = 0 Until FMWIDTH
FactoryMap[x, y].id = Readint(f2)
Next
Next
Print "Yay - Loaded"
Else
End
EndIf
Next
Basically I store what GetChar gets in Line$. I then use an eachin loop to detect if line = f.id. If it equals f.id it loads the correct map according to what number was input. When I add an... else end it quits even if the correct f.id was picked. Why is it doing this? |
| ||
| Yep, Just tested it again. With the second bit of code I posted, if I remove the "else" and any code in it whether it be "End" or "Exit" or some other code, the file loading works perfectly. This is what the code looks like when it works.
If MapIdSelected = 1
'TTile2.MapClearMap
Print "2"
For Local f:TFile = EachIn TFile.FList
Print "3"
If Line$ = f.id
Print "4"
File = f.MapName
f2 = ReadFile("usermaps/" + File)
For Local y:Int = 0 Until FMHeight
For Local x:Int = 0 Until FMWIDTH
FactoryMap[x, y].id = Readint(f2)
Next
Next
Print "Yay - Loaded"
EndIf
Next
|
| ||
| I think I know why it's doing this. I'm checking if Line$ = f.id and if not then to either exit or do other stuff. Now, it's by default not going to = f.id because I'm looping through them all and if at any time in the loop it doesn't equal one of them it quits. So, that leaves me to try and figure out how to detect the correct id without looping through the lot of them and checking if LIne$ equals it. MY God I'm a Geniusly Powerfull Dumb Ass. :) |
| ||
| I Fixed it. :) I Used the variable TFile.TempID. Basically I added 1 to that variable every time a new file was detected. So I checked if Line$ was less than TempID-1 and if it wasn't then quit the loading process. Case (char = 13) If Line$ <= TFile.TempID - 1 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.DoneLoadingMaps = 0 Exit EndIf That took 1 hour to figure out. :/ In my defence though it is 2.30 am in the Morning here in London. :) |