SaveString problem.
Monkey Forums/Monkey Programming/SaveString problem.
| ||
Why does SaveString give me the error: "Identifier 'SaveString' not found."?, when it is clearly listed in the documentation. :-/ |
| ||
I forgot to add this... I'm using version 76d with Jungle Ide. |
| ||
Seeing as you haven't given any code this is a guessing game. Is there a prize? Let me see: Because you haven't imported the os module? Because you're building for a target that doesn't support the os module (although that should error differently)? Because you actually mean to call SaveState? Let me know if I'm warm. |
| ||
The code is for a monkey version of Mutant Monty, it is a very long source code. I already use LoadString to load the levels, but wanted to use the SaveString function to save-out the high score and again use LoadString to reload it every time the game is loaded. Here are my two functions that I want to use for the purpose that I stated above. Function SaveHighScore:Void() 'This is the problem function !!!. SaveString(bonusScore, "info/highscore.dat") End Function LoadHighScore:Void() Local state:String = LoadString("info/highscore.dat") if state bonusScore = Int(state.Trim()) Else bonusScore = 0 EndIf End |
| ||
Some options... * Use LoadState/SaveState instead. * import os (desktop/stdcpp only) and use os.SaveString. * import brl.filestream (android/ios/winrt/desktop/stdcpp) and use the FileStream.WriteString method. |
| ||
Thanks Mark, I will try those options. ;) |
| ||
I have now used the SaveState/LoadState option. It reloads the highscore when the game is restarted with the spacebar, but if I close the browser or the tab the game is running in, or refresh the page, it resets the highscore back to zero. This is happening in both the HTML5 and Flash targets. :-/ |
| ||
OOPS!... I forgot the code.Function SaveHighScore:Void() SaveState(highScore) End Function LoadHighScore:Void() Local state:String = LoadState() if state bonusScore = Int(state.Trim()) Else bonusScore = 0 EndIf End |
| ||
It is normal that it will be deleted sometimes when you close the browser in HTML5. With a live game, it doesn't happen. About flash I can't say, but I imagine that it is the same. |
| ||
OK, thanx Mike. ;) |