I’m super excited to be making my first-ever mobile game. I’ve built out a prototype and was able to figure out how to set up Firebase for authentication.
Now, I’m in the process of setting up the saving and loading so that when you enter the game or into a new scene your stats are loaded / progress is saved during play.
It’s a very simple game. I have one external layout & external event sheet for the main character and its actions and then I have a bunch of very simple scenes the player goes through.
My thinking about how to set this up was when my global variables change (Game States, like the scene you’re on, or User Details like the player’s level) I update a field of a document. This seems to be possible for the saving part. As I moved on to loading, however, I thought to try “Get a field of a document” but I can’t store the value into a global variable, only a scene variable.
The Ask: Do I need to go into every single scene now and set up all of my variables again as scene variables? Would I then transition them into global variables at the beginning of a scene via my external event sheet? Or do I need to also have the change scene variable to global variable at the scene event level?
Currently, as a prototype, I have about 30 scenes… That process already sounds like a tedious nightmare… If I grew this to say 100 scenes though?
Is my thinking about this correct? Is my process totally way off? Can anyone help point me in the right direction?
I’ve tried checking out the wiki here and watched some youtube videos but I’m still not certain. If you have any other resources you could point me to on the topic, i’d be forever grateful!
Im really confused because my external event sheet looks like its set specially to Scene A. So if i dont declare the scene variables, and then go to Scene B, will my external events still work?
Are you setting this at the scene level or an external event level?
I have 10 variables and 30 scenes. Multiply that by 2 (for adding a change scene variable to global variable action) and i’ll need to add 600 more actions into my game to make loading work???
Can we not just make write field to global variable a thing?
I’m not sure what you mean. You only need to do this once in your first scene, then the loaded global variables are available in every scene and every external sheet.
As option 4 there is also the possibility to save it as JSON, then all childs of a global structure variable are filled with one action.
For the beginning, with only 10 variables, I would live with the 10 extra actions to convert scene to globe.
woah, just blew my mind. okay, so wait. Does this also include my resource bars? If I load the resource bar at sign in, it will automatically update itself at every scene? Variables also change things in the game, like an objects animation, or an item unlock, etc. These would all just get loaded by themselves in every new scene started?
hmmm… that’s a thought… I had them under two structures, but maybe I just do only one…
A problem will be the delay when loading from database.
The UID expression will be empty in this place. And converting scene to global variables does not work directly after the load field action. There must be an extra event that is executed when the result state variable is “ok”.
Because of the rules, I think it should be match /Users/{document=**} {
Last scene will = 1 & firebase will load game_state.hunger to scene variable… here I should add a condition … something like wait 0.5 seconds if the result is “ok” and then set the global hunger variable? I guess I’ll repeat this for the rest of them (hunger, sleep, scene, etc) breaking it up into where I have a bunch of checks for the same condition, (i.e., “if scene = 1”) but separated with their own actions (next is sleep) & conditions (wait)? … should I also wait with the write actions?
Update
Instead of many Get fields, you can use the Get document action if you have a scene structure variable, with children who have the same names as the database fields.
hey @jack thank you so much for all your support! You are the best. Seriously!!!
Using documents over fields was better. I ended up having to do some really funky stuff with my scene variables since writing or loading global variables to documents is not an option.
I’m now writing & loading as expected to the database, woohoo.