SaveString problem.

Monkey Forums/Monkey Programming/SaveString problem.

Steve Ancell(Posted 2014) [#1]
Why does SaveString give me the error: "Identifier 'SaveString' not found."?, when it is clearly listed in the documentation. :-/


Steve Ancell(Posted 2014) [#2]
I forgot to add this...

I'm using version 76d with Jungle Ide.


muddy_shoes(Posted 2014) [#3]
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.


Steve Ancell(Posted 2014) [#4]
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



marksibly(Posted 2014) [#5]
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.


Steve Ancell(Posted 2014) [#6]
Thanks Mark, I will try those options. ;)


Steve Ancell(Posted 2014) [#7]
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. :-/


Steve Ancell(Posted 2014) [#8]
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



MikeHart(Posted 2014) [#9]
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.


Steve Ancell(Posted 2014) [#10]
OK, thanx Mike. ;)