Hi!
I've been staring at and re-writing this ****** code for what seems like eternity. I really don't understand why this does not work as intented.
Some background: When the player has completed the level (level identifier stored in
) and are returning to the main screen I have this code running:
If GetRawKeyPressed ( 32 ) = 1
OpenToRead ( 1 , "save.data" )
For i = 1 to Level_Max
Level[i].tempStatus = ReadInteger ( 1 )
Next i
CloseFile ( 1 )
OpenToWrite ( 1 , "save.data" )
For i = 1 To Level_Max
If i = level_loader
If Val ( GetTextString ( HUD_Coins_Text ) ) = Level_Data_File_CoinCount + Level_MapData_File_Monsters * 4
If Level[i].tempStatus = 1
WriteInteger ( 1 , 2 )
Else
If Level[i].tempStatus = 2
WriteInteger ( 1 , 2 )
EndIf
EndIf
Else
If Level[i].tempStatus = 1
WriteInteger ( 1 , 1 )
Else
If Level[i].tempStatus = 2
WriteInteger ( 1 , 2 )
EndIf
EndIf
EndIf
EndIf
If i = level_loader + 1
If Level[i].tempStatus = 0
WriteInteger ( 1 , 1 )
EndIf
EndIf
Next i
CloseFile ( 1 )
OpenToRead ( 1 , "save.data" )
For i = 1 to Level_Max
Level[i].Status = ReadInteger ( 1 )
Next i
CloseFile ( 1 )
.........
What this is supposed to do is set a value in the file "save.data" corresponding to the level. This value can be:
0 = Locked
1 = Unlocked
2 = Star
First I run a quick loop through all the levels and get the status of each of the levels. (Level_Max = How many levels there are)
Then what I do is call:
If Val ( GetTextString ( HUD_Coins_Text ) ) = Level_Data_File_CoinCount + Level_MapData_File_Monsters * 4
This basically checks if the amount of coins you collected = possible amount of coins. This code works... Tested.
After that, if you collected all the coins, I change the status of the level to 0/1/2 depending on what the status was before. If it was unlocked then it is set to 2 (star), if it was 2 then it remains 2.
If you didn't collect all the coins and it was unlocked it remains unlocked... If it had a star, it keeps the star.
Then I check if the level after the current level (level_loader + 1) is unlocked, if it isnt, i unlock it.
Finally I save the lot and update it.
This works on level 1. Level 2 is unlocked and all that stuff...
However, when I try level 2... The status is never changed to 2 and level 3 is never unlocked???
Hope I've explained good enough! xD
Thanks!
PS: All the variables:
level_loader
Level_Max
Val ( GetTextString ( HUD_Coins_Text ) )
Level_Data_File_CoinCount + Level_MapData_File_Monsters * 4
behave as they should.
cheers