Preserving State Between Pages - Help

Hey guys.

In the tab bar sample, if any of you have played around with it. If you create say custom buttons with values on any of the tab screens - so say you had a image that displayed an integer, and that value got changed on touch. Simple yeah? Right…

So you do that then you change tabs and upon returning to your previous tab you see that the integer value is reset back to its default value.

I have tried multiple ways of bypassing this behavior, but it seems to be unavoidable. Seems integrating a state controller (aka finite state machine) into corona is a hard task…

I personally have used lua on and off for over 6 years, and have even made a tool similar to corona for the psp (google LuaPlayer Euphoria), and find some of the ways Corona deals with things a bit bizarre and overly complex, like the hard things are easy and the simple things are hard. It really should not be so complex to create a simple 3 screen app and have it not reset values between page changes…

Anyone got any suggestions or code to prevent this from happening ? I’m at my wits end.

Two apps i have had to put on hold because of this. Another app I created a state machine and eventually got it to go between menu > game fine, however (even though i am tidying up after myself) after doing this several times, all my movement, animation and everything else in the game simply froze and all i could do was return to the menu.

It’s pretty disappointing how hard it is to do something so simple, especially when you know how simple it should be to do and how hard it is being made. [import]uid: 6981 topic_id: 2978 reply_id: 302978[/import]

I think all you need is a central location to store the state data persistently. Could be as simple as a global table. So, “screens” could just store or read values from this table when they go or come back.

You might also use this table to store values that go to disk, using a JSON library perhaps. [import]uid: 4454 topic_id: 2978 reply_id: 8584[/import]

infuseddreams, I fully agree with you, “hard things are easy and the simple things are hard”!

In my last post (http://developer.anscamobile.com/forum/2010/10/19/slider-and-volume-control), I said I feel a little bit alone, but now it’s getting better.

I have a similar situation to keep the last value of a slider when I change screen. The value is reset upon returning to the previous screen. And how to do a central location?.. that’s another question…
THANKS in advance for a code example.
[import]uid: 8970 topic_id: 2978 reply_id: 8590[/import]

In your main.lua, you can setup a global table like this:

globalDataHolder = {}  
globalDataHolder.screen1Data = {}  
globalDataHolder.screen1Data.someValue = ""  

We’re excluding “local” here, so other modules or objects can see it. In your screen code, you reference it to read or store like this:

[code]
– Upon Entry
local myValue = globalDataHolder.screen1Data.someValue

– From here we can use this value, or change it
myValue = “new value”

– Upon Exit
globalDataHolder.screen1Data.someValue = myValue
[/code] [import]uid: 4454 topic_id: 2978 reply_id: 8591[/import]

Will give that a go :slight_smile:

It shouldn’t really require all that extra work, but a solution is a solution i guess. (Unless corona redesigns the api a tad, hopefully Carlos took home some of my points)

Thanks :slight_smile: [import]uid: 6981 topic_id: 2978 reply_id: 9290[/import]