[Plugin] Globals

Post your completed addons to share with the community

Post » Mon Feb 13, 2017 4:26 am

I understand why having a Global Variable the user can't change freely during game play is considered a problem.

I have global variables that the user can freely change in game settings or game play, are these considered unsafe Global Variables? They are limited by conditions and only effect the player changing them.
B
65
S
37
G
13
Posts: 240
Reputation: 12,703

Post » Mon Feb 13, 2017 2:01 pm

Unconnected wrote:I understand why having a Global Variable the user can't change freely during game play is considered a problem.

I have global variables that the user can freely change in game settings or game play, are these considered unsafe Global Variables? They are limited by conditions and only effect the player changing them.


I'm sorry but I don't understand what you mean exactly. You can change global variables during gameplay and they are safe to use from security perspective... and I think you know that... could you please rephrase your question?
ImageImageImage
B
27
S
16
G
80
Posts: 1,014
Reputation: 44,747

Post » Mon Feb 13, 2017 8:56 pm

A Global Variable that if changed could ruin the game or allow cheating versus a global variable that when changed won't effect game play or allow cheating.

Something like a Global variable that sets the game limits, versus one that would allow something like a name change or a color change.

Are both considered dangerous or just all Global Variables?
B
65
S
37
G
13
Posts: 240
Reputation: 12,703

Post » Mon Feb 13, 2017 10:33 pm

I don't remember I ever said that C2 global variables are dangerous in any way.

Well, if one has a global var which value change can unintentionally make a mess on the runtime then it means his code architecture is crying a river.

Please read my article linked in the first post here. I think it will clear things out for you.
ImageImageImage
B
27
S
16
G
80
Posts: 1,014
Reputation: 44,747

Post » Tue Feb 14, 2017 1:55 am

I did, it is why I asked...

I misread Issue #4 apparently.

Thanks for the plug in.
B
65
S
37
G
13
Posts: 240
Reputation: 12,703

Post » Tue Feb 28, 2017 2:24 pm

@ashley, is this something worth concidering for C3? Or not necessary anymore, because C3 is built in a different way?
B
28
S
6
G
7
Posts: 678
Reputation: 5,676

Post » Tue Feb 28, 2017 2:59 pm

I think if you have tons of globals you could do a lot to refactor your events.

In particular static local variables are designed as a substitute for globals but just scoped to the events that use them. For example you could use 10 static locals inside a group, when only just that group uses them, and they never appear anywhere else in the event system, and the variables themselves are close to where they are used. I think this is an under-used feature and would do a lot to solve the "global overload" problem.
Scirra Founder
B
397
S
236
G
88
Posts: 24,423
Reputation: 194,560

Post » Wed Mar 08, 2017 4:20 am

@Ashley
I think the default settings for local variable should be static.
I also think that it would be nice to have static instance variable.
B
41
S
16
G
7
Posts: 55
Reputation: 6,498

Post » Wed Mar 08, 2017 11:08 am

Instance variables are already static, because they don't reset every tick.
Scirra Founder
B
397
S
236
G
88
Posts: 24,423
Reputation: 194,560

Post » Wed Mar 08, 2017 12:18 pm

@Ashley
"static instance variable" across the all the instances of a sprite for example.
we have object sprite A with instances A1 A2 A3, they have a static variable called total shots fired. (its just 1 integer in memory).
(so things can be just a little bit closer to oop)
B
41
S
16
G
7
Posts: 55
Reputation: 6,498

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 1 guest