Static non-global variables

Discussion and feedback on Construct 2

Post » Thu Dec 31, 2015 4:47 pm

I was wondering if it is possible to have such variables, used much like instance variables but for objects that don't have multiple instances (such as the mouse). From what I can find this doesn't exist which means I have to use global variables in a lot of cases. Sometimes global variables are overkill for the task at hand, which is where these sorts of variable really help.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Thu Dec 31, 2015 6:14 pm

No, i think you might have to just settle for global variables, i mean if they work than i don't think they'd put in a third option. check the manual, it would be in there if there was a third method to variables.
B
24
S
9
G
5
Posts: 17
Reputation: 3,723

Post » Thu Dec 31, 2015 6:17 pm

If you are working on a big project though, you may need a lot of variables and if they are all global like they are now surely they start to become disorganised and begin to impact workflow.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Thu Dec 31, 2015 6:19 pm

briggybros wrote:If you are working on a big project though, you may need a lot of variables and if they are all global like they are now surely they start to become disorganised and begin to impact workflow.


Yes that is what I am experiencing at this moment sadly.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 31, 2015 6:25 pm

You can create a group with a blank sub-event and add static local variables. All the appropriate code would then be in the group with access to those variables.
ImageImageImage
B
71
S
21
G
233
Posts: 3,696
Reputation: 130,368

Post » Thu Dec 31, 2015 7:10 pm

@blackhornet Thank you, this helps a lot! However, I still think it would be better if this could be used more intuitively.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Fri Jan 01, 2016 7:57 pm

plan A: Add a new event sheet, move some global vars into it, close the sheet. Now it's clean.
Plan B: use a dictionary object, put move some vars to it. Dictionary should be global by default.
Providence University, lecturer.

Tatung University, lecturer.



Consultant per question: USD$15 / time

Consultant by month: USD$300 / month

Customized project: USD$2500 / capx
B
78
S
16
G
4
Posts: 196
Reputation: 7,688

Post » Fri Jan 01, 2016 8:19 pm

@Jomo has a good point. I also add global sprites and use them as variable containers. The downside is you must make sure these objects exist on every layout or create them at the start of layouts you will need them on. I have an object called Global and then a bunch of instance variables on it. When I want a variable I simply say Global.whatever. Makes it easy for me.
Image
B
33
S
11
G
2
Posts: 564
Reputation: 5,153


Return to Construct 2 General

Who is online

Users browsing this forum: Kyatric and 11 guests