Corona Geek #126 - Sharing Data Between Composer Library Scenes

Got a topic or guest suggestion? Share it here.

 

Want to be on the Hangout to discuss your app or a specific topic? Let us know and we’ll set something up.

 

Once the Hangout is published you can discuss the show topics on this thread.

 

Update:

 

During last week’s Hangout we continued the discussion around using Composer library to manage scenes in apps. We looked at how memory usage varies between managed and unmanaged scenes. We also examined the differences between Corona SDK memory management of objects and Lua memory management.

 

Replay Hangout #125:

https://www.youtube.com/watch?v=4jdDkLW-upM

This week we’ll continue the discussion with a look at more scene optimization tips, including how to share data between scenes. We’ll also look at custom Composer scene transitions. Scene management is an important part of app development. Join the Hangout on Monday and be part of the conversation.

Congratulations   ** #ShipJam ** Winners

Great news, the judge’s votes are in from the end of year competition to ship an app before the end of 2014. It was a tight competition and all the judges were impressed by the quality of work and how much participants got done in such a short time.

The top three awards went to

First Place:  Fantasy Night Football by Noah Malewicz, Chunky Apps,http://chunkyapps.com
Second Place:  Pet Puzzles by Scott Adelman,http://scottadelman.com
Third Place:  MisionTierra by Raptor UVG, http://raptoruvg.com.mx

Judge’s Choice  went to: Long Vowels Word Study by Thomas Wilson, Out Of Touch Productions, http://thisreadingmama.com

Great job to everyone and thank you to Laura Tallardy and Eric Kinkead for inspiring the Corona community to push out one more app before the end of the year. You guys rock!

http://shipjam.weebly.com/contestants.html

January’s Geek Games – Last Week To Play!

In January we’re playing Chip Chain on iOS or Android ( http://chip-chain.com/ )  for the chance to win a $50 gift card.

The rules are simple. Match chips in under 2 minutes, then post a photo of your high score on the Corona Geek Facebook wall (https://www.facebook.com/CoronaGeek ) for a chance to win. The winner will be announced on February 2 when we announce the next game to play.

Download Chip Chain now and start playing ( http://chip-chain.com/ ). Good luck!

Discuss the Hangouts
http://forums.coronalabs.com/forum/591-corona-geek/

Suggest Hangout Topics
http://forums.coronalabs.com/topic/53368-2015-hangout-topics-and-guest-suggestions/

Ask Questions
http://coronageek.com/questions

Be a Hangout Guest
Email coronageek@coronalabs.com and let us know.

Rate Corona Geek on iTunes:
http://bit.ly/18b9A8r
Your 5 star ratings help us grow the community.

ShipJam should be wrapping up then? Maybe it will be wrapped up? If not maybe 127 for it? 

http://shipjam.weebly.com/

Sounds like a good idea. How much time do you think we would need to set aside?

Hi Charles & Ed

Just watched this Hangout and having asked the question regarding composer library scenes shared & persistent data  (which I now fully understand :) )  I must say that all the last three hangouts have really assisted me in my understanding and development using the composer library, I real must watch for anybody developing in Corona SDK.

Many Thanks!!!

Thanks to all for the in-depth tut.

Ed.

On looking at your persistent data example am i right in that if we were to add effectively the table.load & table.save into the persistent data module ( with slight changes of course , ie detaching them from the table “array/table”) then we would be able to have a stand alone module, correct?

something like this

[lua]

local myPersistentData = {}

function myPersistentData.tableLoad( fileName, base )

local base = base or  system.DocumentsDirectory

local path = system.pathForFile( fileName, base )

local fh, reason = io.open( path, “r” )

if fh then

local contents = fh:read( “*a” )

io.close( fh )

local newTable = json.decode( contents )

return newTable

else

return nil

end

end

function myPersistentData.tableSave( theTable, fileName, base, doStrip )

local base = base or  system.DocumentsDirectory

local path = system.pathForFile( fileName, base )

local fh = io.open( path, “w” )

if(fh) then

fh:write(json.encode( theTable ))

io.close( fh )

return true

end

return false

end

local theData = myPersistentData.tableLoad( “myPersistentData.json” ) or {}

myPersistentData.store = function( )

myPersistentData.tableSave( theData, “myPersistentData.json” )

end

myPersistentData.get = function( name  )

return theData[name]

end

myPersistentData.set = function( name, value, autoStore )

theData[name] = value

if(autoStore) then myPersistentData.store() end

end

– Set Defaults

local defaults = {}

defaults[“count”] = 0

for k,v in pairs(defaults) do

theData[k] = theData[k] or v

end

myPersistentData.store()

return myPersistentData

[/lua]

T. 

@ToeKnee,

Yes.  You don’t have to ‘extend table’, but can instead take those same functions and put them directly in the persistent memory module.  I do it the prior way because table extensions are part of SSK which I use in all my projects.  

However, making the module stand-alone is an excellent idea!  

Cheers,

Ed

ShipJam should be wrapping up then? Maybe it will be wrapped up? If not maybe 127 for it? 

http://shipjam.weebly.com/

Sounds like a good idea. How much time do you think we would need to set aside?

Hi Charles & Ed

Just watched this Hangout and having asked the question regarding composer library scenes shared & persistent data  (which I now fully understand :) )  I must say that all the last three hangouts have really assisted me in my understanding and development using the composer library, I real must watch for anybody developing in Corona SDK.

Many Thanks!!!

Thanks to all for the in-depth tut.

Ed.

On looking at your persistent data example am i right in that if we were to add effectively the table.load & table.save into the persistent data module ( with slight changes of course , ie detaching them from the table “array/table”) then we would be able to have a stand alone module, correct?

something like this

[lua]

local myPersistentData = {}

function myPersistentData.tableLoad( fileName, base )

local base = base or  system.DocumentsDirectory

local path = system.pathForFile( fileName, base )

local fh, reason = io.open( path, “r” )

if fh then

local contents = fh:read( “*a” )

io.close( fh )

local newTable = json.decode( contents )

return newTable

else

return nil

end

end

function myPersistentData.tableSave( theTable, fileName, base, doStrip )

local base = base or  system.DocumentsDirectory

local path = system.pathForFile( fileName, base )

local fh = io.open( path, “w” )

if(fh) then

fh:write(json.encode( theTable ))

io.close( fh )

return true

end

return false

end

local theData = myPersistentData.tableLoad( “myPersistentData.json” ) or {}

myPersistentData.store = function( )

myPersistentData.tableSave( theData, “myPersistentData.json” )

end

myPersistentData.get = function( name  )

return theData[name]

end

myPersistentData.set = function( name, value, autoStore )

theData[name] = value

if(autoStore) then myPersistentData.store() end

end

– Set Defaults

local defaults = {}

defaults[“count”] = 0

for k,v in pairs(defaults) do

theData[k] = theData[k] or v

end

myPersistentData.store()

return myPersistentData

[/lua]

T. 

@ToeKnee,

Yes.  You don’t have to ‘extend table’, but can instead take those same functions and put them directly in the persistent memory module.  I do it the prior way because table extensions are part of SSK which I use in all my projects.  

However, making the module stand-alone is an excellent idea!  

Cheers,

Ed