I am using the Director class in my game and want to save the game state when the app is supended by hooking into the following
local onSystemEvent = function( event )
if "applicationSuspend" == event.type then
All my game code is held in a file called Screen2.lua whereas this onSystemEvent code is in my main.lua
Hence my question is how do I go about saving all the local variables inside Screen2.lua to enable me to resume the game?
Sorry probably a basic question but I am still haven’t quite got my head round communication between modules and want to implement as efficient a solution as possible.
Perhaps someone has an example of saving and resuming game state using the Director class?
Any advice much appreciated.
Thanks
Paul [import]uid: 7863 topic_id: 5113 reply_id: 305113[/import]
One caveat: make sure you don’t store an editable format. User can have access to the saved file, so it is possible for users to just edit the number of gold or items for cheating. Use crypto.hmac for encrypted message digest. [import]uid: 11334 topic_id: 5113 reply_id: 16869[/import]
Thanks newbie101 - I think I may have phrased my question badly. What I really needed to know was how to get the data from Screen2.lua to main.lua so I can call a save game state function. I think I have worked it out now using a similar solution as to what I used to save local achievements. Just means I need to keep updating the game state variables after every turn in my game but guess that is not a problem.
I was thinking alternatively there was a way of accessing a variable in Screen2.lua from main.lua but as all my variables are local, I can’t see how this would be done.
So in psuedocode, something like
local variableRetrievedValue = Screen2.variable1
Great suggestion regarding encryption - I hadn’t thought that people could access these data files so easily
[import]uid: 7863 topic_id: 5113 reply_id: 16878[/import]
I will give that a go though I had thought there was a performance hit with global variables.
My game is a football game and I need to store the position of all the players on both teams and also the ball position, score etc so quite a few variables to save. [import]uid: 7863 topic_id: 5113 reply_id: 16882[/import]
I solved that problem using the director itself, because the director variable is available inside the file, it’s like having a namespaced global variable.
here is an example:
setting: (some other stage files)
director.carrier.selected_stage_from_map = i
getting:(getting from other stage files)
current_stage = director.carrier.current_stage_from_map [import]uid: 11334 topic_id: 5113 reply_id: 16883[/import]
Guys, please write your questions at Director’s sub-forum. I don’t have too much time to answer and I really didn’t see most of the topics created for Director. I’m sorry for that and I will appreciate if you all could go to this link: