[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 for C2 Globals.c2addon
Download for C3 Globals.c3addon

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.

== UPDATE - New extended version ==

Image

Globals 2.0 is now available in Scirra Store (note that Globals v1.0 is still and will remain free).

Globals 2.0 is an extended version of Globals plugin with the following extra features:
  • Compatible with Globals 1.0
  • Save/Load variables to System storage
  • Save/Load variables to LocalStorage (or any other place by export/import JSON)
  • Reset variables
  • Can be used as a "struct" data object

For more details and the video please visit the Globals 2.0 store page.
Last edited by BackendFreak on Mon Aug 21, 2017 11:51 pm, edited 6 times in total.
ImageImageImage
B
27
S
16
G
79
Posts: 1,012
Reputation: 44,243

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
44
S
18
Posts: 178
Reputation: 3,566

Post » Mon Jan 09, 2017 3:41 am

This is exactly what I was looking for :D thanks man this is great!
B
78
S
35
G
22
Posts: 85
Reputation: 17,013

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".
ImageImageImage
B
27
S
16
G
79
Posts: 1,012
Reputation: 44,243

Post » Wed Jan 11, 2017 7:54 pm

Very good! Clever solution, i'll use this plugins in my projects.
B
36
S
5
G
2
Posts: 28
Reputation: 2,448

Post » Wed Jan 11, 2017 11:49 pm

What are difference between this plugin globals and c2 globals?
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

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
ImageImageImage
B
27
S
16
G
79
Posts: 1,012
Reputation: 44,243

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
86
S
43
G
71
Posts: 601
Reputation: 43,619

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
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

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.
ImageImageImage
B
27
S
16
G
79
Posts: 1,012
Reputation: 44,243

Next

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 1 guest