Best practice for saving common variables

0 favourites
  • 9 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • I'm looking for answers to this question in more of a "in your opinion" way than not actually knowing how to do it, so I hope this is the most appropriate place to ask.

    So, I've been working on a project for a while now and I have two modes (single and multiplayer). When I made the single player a long while back, I made a TON of global variables for "global" things, like checking if the game is paused, checking if sound is on/off, etc. Later, working on the multiplayer, I realized how excessive my globals were getting and made an invisible "multiplayerVariables" sprite that tracked a bunch of stuff, but of course, that also feels a little excessive.

    I've been doing a lot of reorganization on this project recently and so I was hoping to hear what others tend to do to keep track of "common" variables in bigger projects like this.

  • Fill an array with everything you want to save.... Save the Arrays Json string to disk, or local storage.

  • I think the Dictionary object will be your friend here. You can declare and check your 'variables' (keys) with built in actions in simple events in one line. You can also put arrays inside them and even objects as json string if you want.

  • I actually think that a object with loads of variables is a good way as well as having array in a file you load trough ajax is good too. And dictionary is possibly good too, but I've barely use it, so can't really say much about it. The question is,which one is most efficient? But I don't know. Personally all ways are good as long as they are easy for you to use, and which ones do the job best for certain tasks. For example, I found it easiest to have a dedicated object with boo's for sequential procedural generation, and arrays in file for scripting ai. And again, I don't really know for what purpose I'd ever use dictionary, when all other option are all I need right now? But will find out sooner or later probably.

  • The only advantage I can think of for Dictionary objects is that you can create keys ad-hoc, during runtime and as you write the event sheets without finding the object and adding the variable. I also put objects onto global layers to store game data etc between layouts. The user-definable pretty pictures for each make it easier to find them in events IMO.

    This is spot on:

    Personally all ways are good as long as they are easy for you to use, and which ones do the job best for certain tasks.

  • "The only advantage I can think of for Dictionary objects is that you can create keys ad-hoc, during runtime and as you write the event sheets without finding the object and adding the variable."- Colludium

    You can insert keys into an array too, they are just not as human readable (the index names are numbers only). Also you can use Regex expression to mimic the search and sort functions of the dictionary.

  • The only advantage I can think of for Dictionary objects is that you can create keys ad-hoc, during runtime and as you write the event sheets without finding the object and adding the variable. I also put objects onto global layers to store game data etc between layouts. The user-definable pretty pictures for each make it easier to find them in events IMO.

    This is spot on:

    > Personally all ways are good as long as they are easy for you to use, and which ones do the job best for certain tasks.

    >

    Thanks! I still hope that c3 will introduce variables catalog thought. It would be so much easier at organizing them, especially with how family variables don't get translated between families families, which to be completely honest could be an option. If not this option, then something else that would speed up workflow. It is all very cumbersome right now. Ashley

  • I put sprites and stuff way off at -9999999 in a global layer. However, I think they still run into each other and overlap. The problem for me is getting a sprite object from one layout to the next. If you make them global they are in every layout, when you just want them in a subset. So you have to move them off to -999999,-9999999.

    yours

    Winkr7

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If you need to save all those variables, then dictionary. Else, use an invisible object. I used to think C2 needed a new feature for vars like this, but I dunno..just using objects might be the best because all the other things you can do with them to save or manage those variables across the whole project.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)