[Feature Request] Global Variables

Discussion and feedback on Construct 2

Post » Tue Oct 21, 2014 1:01 am

Hi!
I think having a better organization within Global / Local variables would be great.
For now, every time I need to use one I have to go through a big list.
Maybe could be organized into sub-categories for better readability?

Thanks!
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Tue Oct 21, 2014 5:03 am

I wouldn't mind having global variables be located somewhere other than on the event sheet, and organizing them into categories would be great. Hadn't really thought about this before, but now that I do it would be awesome.
B
5
S
2
Posts: 11
Reputation: 1,197

Post » Tue Oct 21, 2014 7:08 am

I put all the Global vars into a separate event sheet and use comments to separate the various differences/uses. Makes finding/managing much simpler.

Not a substitute for your suggestion, I know, but a stop-gap alternative..
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
86
Posts: 5,414
Reputation: 59,512

Post » Tue Oct 21, 2014 2:20 pm

I do the same, separate sheet with comments, But I find it difficult when it comes so adding them via System - etc. All the variables are listed by alphabetical order. Perhaps could be via sub categories so it could match the comments/name for each category in the var sheet.
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Tue Oct 21, 2014 2:40 pm

Personally for Globals. I like to make a Dictionary set it to global. Then make my globals in that object. I personally don't like cluttering up the variable scope with lot's of var globals.

So there you go. Proper globals associated with a class rather that floating in memory space.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,028

Post » Tue Oct 21, 2014 4:31 pm

@jayderyu, that seems like a great suggestion. Ill be trying that :)
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Tue Oct 21, 2014 5:40 pm

@jayderyu

That's a good suggestion. I still like having certain values as normal globals so I can tweak them easily during development. Also, the one drawback with the dictionary is a lack of auto-fill. However, there are a lot of less important global values that would be much better off in a dict like you suggest.

Another approach is to create a global sprite, and place it on a global layer. Then, add instance variables to it. This way you don't have to worry about mis-spells, you have auto-complete, and you still avoid cluttering up the top-level scope with normal globals.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Tue Oct 21, 2014 5:45 pm

Global variables make sense, for constants, and for other things like character names, location, play time, etc.

For a RPG Character Database it is global as the info is accessable at every point in the game, now game dialog can be local as it's only called locally not globally.
Working on a Action RPG
B
8
S
4
G
4
Posts: 18
Reputation: 2,734

Post » Tue Oct 21, 2014 8:43 pm

This gets asked around some times. Here's two of my posts on the subject:
Post 1
Post 2

also see this and this (both in the same thread), where I suggest cosmetic (aka, interface-only) solutions to the problem.

Keep in mind that the solution only involves changes to the IDE, the engine itself need not be affected. In fact, since each variable can only be in one group (a tree structure), all the engine has to do is concatenate the parents to get the final variable name. So player.ship.resistances.fire could be converted to "playershipresistancesfire" on exporting. It seems pretty simple to me, but only Ashley can say with certainty how hard it would be to change the IDE (I hear it's a bit painful).

While the solution above applies to instance variables, there's no reason a similar scheme can't be applied to global/local variables as well.
B
36
S
8
G
8
Posts: 532
Reputation: 6,903

Post » Wed Oct 22, 2014 2:39 am

jayderyu wrote:Personally for Globals. I like to make a Dictionary set it to global. Then make my globals in that object. I personally don't like cluttering up the variable scope with lot's of var globals.

So there you go. Proper globals associated with a class rather that floating in memory space.



I like this solution. I'll be using it for now. Seems obvious now that you say it.
B
5
S
2
Posts: 11
Reputation: 1,197


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 14 guests