[Plugin] Globals

0 favourites
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Let me quote myself here as I would write pretty same thing as in my article anyway.

    [quote:3h7zaz9f]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 ==

    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.

  • Got it!

    [quote:1v9pvzcm]

    "...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..."

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This is exactly what I was looking for thanks man this is great!

  • I added a little update to the first post, explaining "why this approach over the native globals".

  • Very good! Clever solution, i'll use this plugins in my projects.

  • What are difference between this plugin globals and c2 globals?

  • 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

  • Could you not accomplish the same thing with, say, a blank dictionary? Am I missing something?

  • > 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?

  • I took a quick read, I see a difference is... just for sorting?

    No it's not just for sorting.

    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.

  • I understood your reason, I guess it would be good practice for code architecture. Thanks for explaining in other way!

  • Could you not accomplish the same thing with, say, a blank dictionary? Am I missing something?

    As I mentioned in my recent post:

    It’s all about the approach. You can use nearly any other plugin and achieve the same result. I just made this one to have an empty plugin so to not load unnecessary data to the memory and have a separate plugin with unique icon to make it visually distinct.

    So yes, you can use a blank dictionary as well. Wouldn't be that elegant (IMO) as using this empty plugin, but you can achieve the same results.

  • I already do it by using a permanent object (say, an array) in my game instead of global variables. The problem is i just recently started this approach and still have tons of globals to turn into object variables with all affected events.

  • I already do it by using a permanent object (say, an array) in my game instead of global variables. The problem is i just recently started this approach and still have tons of globals to turn into object variables with all affected events.

    That's why it is recommended to use this approach always from the start of the project (from the very first global variable) and have things encapsulated all the time. Refactoring the existing project is always time consuming. Still if you have "tons" of globals it most probably mean your app architecture is not the best it could be. Whenever it is possible you should use local variables instead of globals.

  • I was totally going to do that! It's kind of like a "struct" object... Great idea!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)