Need Help With Variables And Connecting Them To Different Scenes

Ok so in my game if you catch a certain amount of items then you get up to three stars. I am using the director class and I have a level “scene” and a menu “scene”. Now, I think, I know the basic idea of how I want to set it up… It would have a “stars.lua” file containing variables for each level and in each level, at the end of the level, it would tally up the score and change the variable on the “stars.lua” file.
The problem is I have no idea how to code this. I have the right code to open the .lua files. Like…

module(..., package.seeall)  
function new()  
 local localGroup = display.newGroup()   
--lots of code in between  
return localGroup  
end  

But I don’t know how to change variables in a separate .lua file. Or maybe I’m completely looking at this the wrong way and if that is the case how would you go about it.

If you are so kind as to answer could you please provide some form of sample code and explain how they work. I’d like to learn as I go.

Thanks for taking the time to read it.

Danny [import]uid: 59140 topic_id: 17524 reply_id: 317524[/import]

you can have something like

local stars = require(“stars”)
stars.score = calculated_updated_score()

and the stars.lua would have the variable score as part of the returned object.

you need to read up a bit on tables and objects to get an idea.

alternatively you can use ICE and save the data into a db and load it from there

or use the _G variable and modify the variable.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 17524 reply_id: 66587[/import]