First, I would like to apologize for not being responsive. I’m on a business trip in Biloxi, MS right now, and well the Roulette wheel has been stealing my time (I’m up $80… starting with $20… for the curious)
Secondly I’m glad you were able to solve that last problem on your own.
You have kind of a problem with your code and it may be leading you to some frustration. You’re mixing using _G and storyboard to hold your game’s information.
Let me try to break this down even finer:
storyboard is a table.
_G is a table.
We are trying to use them to pass information from one module to another because both tables are visible in your various storyboard scene files.
You can add new variables to either (or both) tables simply by saying:
storyboard.someVariableNameYouMakeUp = “fred”
or
_G.someVariableNameYouMakeUp = 12
They are of course different variables since they are in different tables, but either one will work to pass the variable’s data to another scene or be used later in this .lua file.
When I do:
storyboard.settings.highScore = 0
I’m adding a variable to a table called “settings”. It’s nothing more than a lua table… except that you can add tables to tables. So in effect I added a table called settings to the table called storyboard. Then I added a variable called highScore to the settings table.
You could very well add the settings table to the _G table if you wanted too and keep your game settings in that table rather than the storyboard table.
So if you imagine for a second that “storyboard” is a big box with lots of slots to hold things and you put another box named “settings” into one of “storyboard”'s boxes, and the “settings” box had slots to hold other things like your score.
Now you are using a function named “saveTable”, which for your convenience has also been added to the big storyboard box. That function expects to things to be passed to it… A table to save and a file name to save the table too.
So the code:
storyboard.saveTable(storyboard.settings, “settings.json”)
says to find the function saveTable in the “storyboard” box and run it. I want to take the box called “settings” which is also in the storyboard box and save that content to a file named “settings.json”.
The storyboard box also now has a loadTable function which will read in a specified filename and stick it into the box of your choice. So when we do:
storyboard.settings = storyboard.loadTable(“settings.json”)
We are looking in the storyboard box where we have conveniently put the loadTable function and we are saying get the contents of “settings.json” and put it in the box “settings” which happens to be in the box “storyboard”.
What you need to take away from this is that you can put any variable, be it a number, a string or another table and add it to “settings”, which you have “settings” added to “storyboard”.
When you code:
storyboard.settings.levelLocked = {false, true, true, true, true, true }
you are saying that level 1 is unlocked, level 2 is locked, level 3 is locked etc.
By doing this, you have added a new table “levelLocked” to your settings table and that levelLocked table holds true or false values for each level of your game.
That way, when you execute this line of code:
storyboard.saveSettings(storyboard.settings, “settings.json”)
Then you have saved your current level locked/unlocked status.
If you want to test if a levels is locked?
level = 1
if storyboard.settings.levelLocked[level] == true then
-- the level is locked
else
-- the level is unlocked
end
[import]uid: 19626 topic_id: 25923 reply_id: 108426[/import]