Any known issues with Flash and SaveState()?

Monkey Targets Forums/Flash/Any known issues with Flash and SaveState()?

PoliteProgrammer(Posted 2013) [#1]
The following code:
Strict
Import mojo
Function Main:Int()
  New Program
  Return 0
End
Class Program Extends App
  Method OnCreate:Int()
    Local state:String = LoadState()
    state = state + "k"
    Print state
    SaveState(state)
    Return 0
  End
End

should print "k" the first time it is run, "kk" the second time, and so on. This works fine for me when compiling for the HTML5 target, but only ever prints "k" for the Flash target, no matter how many times it is run. So, I guess my question is; are there any known issues regarding Flash and SaveState()/LoadState(), or am I just doing something wrong?


Origaming(Posted 2013) [#2]
hi, check your Flash Global Storage Settings,,


PoliteProgrammer(Posted 2013) [#3]
Okay, good to know that this is probably just me, but what am I looking for, exactly? I already have global storage settings such that third-party data can be stored, and I've cranked the allowed disk space to unlimited, but I still get the same problem.
I also have no problem storing data from other Flash games that I've tested; it is just my own Monkey/Flex-produced swf with which I have this problem.

EDIT: here's an extension on the original example; this time, the saved data is read again without needing to close the program, which eliminates the possibility of my local data somehow getting flushed.
Strict
Import mojo
Function Main:Int()
  New Program
  Return 0
End
Class Program Extends App
  Method OnCreate:Int()
    Local state:String = LoadState()
    state = state + "k"
    Print state
    SaveState(state)
    Local state2:String = LoadState()
    state2 = state2 + "k"
    Print state2
    SaveState(state2)
    Return 0
  End
End

On a single run of this program this should produce the output "k//kk" (tested and works fine in HTML5), but only produces "k//k" in Flash for me.

Edit 2: I've tested this in both Firefox and Internet Explorer (I'm on Windows), and the problem is there in both. Interestingly, when I right click the Flash window and select settings it says "Currently used: 0kb", so SaveState() really doesn't seem to be working, even though my flash storage settings seem fine.

Another interesting fact; in debug mode, SaveState() works (kk gets printed), but it still isn't persistent to the next run of the application. I'm not closing MServer, by the way.
In release mode, it still doesn't even work between the two successive calls of SaveState(), e.g. in the code given immediately above.

Any advice, please?


slenkar(Posted 2013) [#4]
which version of monkey are you using? I thought the right-click menu was disabled


PoliteProgrammer(Posted 2013) [#5]
I'm using v67b, and the right-click menu definitely works for me. Would stepping back to the latest stable release be a good idea?


siread(Posted 2013) [#6]
Do you fix this PoliteProgrammer? SaveState/LoadState dosn't seem to be working for me in 70b. Refreshing the page or restarting browser wipes everything. It's fine on HTML5.

Looks like Raul might be suffering the same thing.


PoliteProgrammer(Posted 2013) [#7]
Hi siread. Fortunately, I was able to revise my project so that I never needed to use SaveState(), but it's still an unresolved issue for me that's going to be a pain when I eventually start my next (more ambitious) game.

Yes, that sounds like my problem. SaveState() fails for me with Flash but works fine for HTML5. Are you (or is he) using Firefox? The example(s) that I gave above fail (in Flash) on Firefox, but work absolutely fine on Google Chrome (and if I recall Internet Explorer too), when I tested it.

I doubt it's either a bug in Firefox or a problem with our local workstations though, for two reasons:
1) I've never had this problem with any other Flash game that I've played; normally, my Flash storage settings are fine.
2) Toggling from Release mode to Debug mode in Monkey mitigates the problem, as I mentioned in a post above.

Perhaps we should flag this as a potential bug with Mark?


PoliteProgrammer(Posted 2013) [#8]
Has anyone given this any further thought? I'll put together a proper example if someone can second my suspicion that this is a bug. If it's not a bug in Monkey, then I'd be very interested in knowing how to resolve it.

Edit:
It looks like Mark will have this fixed in the next release, or we can work around it ourselves in the meantime, if necessary.
http://www.monkeycoder.co.nz/Community/posts.php?topic=5153