[Plugin] Globals

Post your completed addons to share with the community

Post » Mon Jan 09, 2017 2:19 am

Let me quote myself here as I would write pretty same thing as in my article anyway.

The discussions whether native C2 global variables are good or not have been raised many times on the Scirra forum and beyond. Some people say globals are ok, some that they’re not. I’m in this second group and that is why I made this plugin


[Download this plugin with Armaldio's Plugin Manager] - just two clicks.
or download Globals.c2addon directly

Please read the short article (more images than text) to unterstand the approach of using this plugin:
Globals – Construct 2 plugin – alternative for native global variables

== EDIT ==
I've been asked several times to explain in more details "why this approach over the native globals". So here is some update to clarify.
Last edited by BackendFreak on Wed Jan 11, 2017 8:16 pm, edited 2 times in total.
Image
B
24
S
11
G
49
Posts: 834
Reputation: 28,228

Post » Mon Jan 09, 2017 2:42 am

Got it!

"...Globals plugin

Globals is just an empty plugin. It does absolutely nothing at all. I has no conditions, no action and no expressions at all (except of some native ones which are automatically added by C2 engine). It does not affect performance nor memory usage of the app at all. So the decent alternative solution for global variables is to use instance variables of Globals plugin. I’ll list some reasons why I find this a decent solution..."
Bitcoin Wallet: 1GCRqZExcP6svMdKGpCaRH4A8QAZtSjXxu
B
26
S
9
Posts: 87
Reputation: 1,876

Post » Mon Jan 09, 2017 3:41 am

This is exactly what I was looking for :D thanks man this is great!
B
39
S
16
G
11
Posts: 75
Reputation: 8,522

Post » Wed Jan 11, 2017 11:32 am

I added a little update to the first post, explaining "why this approach over the native globals".
Image
B
24
S
11
G
49
Posts: 834
Reputation: 28,228

Post » Wed Jan 11, 2017 7:54 pm

Very good! Clever solution, i'll use this plugins in my projects.
B
18
S
3
G
2
Posts: 25
Reputation: 1,792

Post » Wed Jan 11, 2017 11:49 pm

What are difference between this plugin globals and c2 globals?
B
104
S
29
G
23
Posts: 3,070
Reputation: 24,781

Post » Wed Jan 11, 2017 11:59 pm

Joannesalfa wrote:What are difference between this plugin globals and c2 globals?


I explained that in my article: Globals – Construct 2 plugin – alternative for native global variables
Image
B
24
S
11
G
49
Posts: 834
Reputation: 28,228

Post » Thu Jan 12, 2017 12:24 am

Could you not accomplish the same thing with, say, a blank dictionary? Am I missing something?
B
71
S
37
G
61
Posts: 566
Reputation: 37,534

Post » Thu Jan 12, 2017 1:14 am

BackendFreak wrote:
Joannesalfa wrote:What are difference between this plugin globals and c2 globals?


I explained that in my article: Globals – Construct 2 plugin – alternative for native global variables



I took a quick read, I see a difference is... just for sorting?
B
104
S
29
G
23
Posts: 3,070
Reputation: 24,781

Post » Thu Jan 12, 2017 1:28 am

Joannesalfa wrote:I took a quick read, I see a difference is... just for sorting?


No it's not just for sorting.

Toby R wrote:It is better to use Globals plugin approach instead of native global variables because:

  • it has the same features as native globals (and more!)
  • it has boolean type variables (not possible with native globals)
  • it doesn’t pollute the variables listing
  • it doesn’t pollute the event sheets
  • it is possible to group variables (not possible with native globals)


Up to that this approach is better semantic-wise and code architecture wise. You may know that modern languages like C# or JAVA do not allow globals at all (for a reason), instead they offer public static variables encapsulated within the class namespace (so basically the same solution as with Globals plugin. You can read a bit more about that in my recent post (if you haven't yet - also linked to the first post here).

Going further, sticking to good practices (following good code architecture and semantics) lets you keep your code clean and intuitive which then implicates in better project maintanability and so on... It's a whole big chain.
Image
B
24
S
11
G
49
Posts: 834
Reputation: 28,228

Next

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 2 guests