Best practice for saving common variables

Discussion and feedback on Construct 2

Post » Sun Oct 18, 2015 2:21 am

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.
B
14
S
2
Posts: 73
Reputation: 794

Post » Sun Oct 18, 2015 2:25 am

Fill an array with everything you want to save.... Save the Arrays Json string to disk, or local storage.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Sun Oct 18, 2015 11:22 am

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.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » Sun Oct 18, 2015 2:32 pm

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.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Sun Oct 18, 2015 4:26 pm

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:
megatronx wrote: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.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » Sun Oct 18, 2015 5:18 pm

"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.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Sun Oct 18, 2015 9:26 pm

Colludium wrote: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:
megatronx wrote: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
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Mon Oct 19, 2015 12:42 pm

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
B
34
S
8
G
3
Posts: 169
Reputation: 3,305

Post » Mon Oct 19, 2015 1:04 pm

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.
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 11 guests