Director \ Data Question

Hi All,

Using the director class, what's the best method to create variables/arrays that are accessible (to read and update) by all director 'scenes' in the app?

Looking for tips on local vs global, where to declare the common variables etc.

Thank you,
Paul

@paulcronin,
you can use the PropertyBag class and save the variables between director scenes.

you can find that at https://github.com/JayantVarma/Rating-Dialog-CoronaSDK

cheers,

?:)

Thanks for the tip, I just checked it out, but I'm not really keen to write to and from a local file just to pass variables between scenes (may cause testing issues between iOS and Android versions).

Is there any way to achieve this by just being savvy with code rather than relying on reading and writing from a local file?

Thank you,
Paul

@paulcronin,
you do not have to save the data to a file, you can use it in-memory. Unless you use the Load/Save functions all data is saved in memory.

Rest is up to you if you want to use that class or not.

cheers,

?:)

If you don't mind breaking encapsulation rules, just have each of your scene's implement a "getState" or "passState" method and then they can read and write to each others "state" (pseudo code) tables.

To be more respectful of encapsulation, make your state table look like this:

state = {}
state.private = {}
state.public = {}

and the "getState() function would only return a handle to:
state.public

so external modules can only write to the non-private area..

views:1552 update:2011/10/2 9:44:12
corona forums © 2003-2011