(Possible Suggestion) Group Global Variables

0 favourites
  • 14 posts
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.
  • I'd like to know the best method for grouping a series of global variables together.

    To explain better, I'd like to make a game that includes many different variables, grouped into different categories, such as:

    Intelligence

         Learning

         Knowledge

         Memory

    Physical

         Strength

         Agility

         Speed

    The list goes on. As you can see, I currently have 6 as shown above, and would eventually refer to these frequently. I'd like to be able to group them so that I can locate them a lot quicker.

    Is the best way to do this to just make a sprite or something, name it the group, and work with instance variables instead? The problem with this method is that I want these 'stats' to remain throughout, so I guess I could make the sprites a global object, but I was hoping there might be an easier way someone's thought of.

  • I have two approaches:

    I have an event sheet reserved for globals. Then they are all together in their own file. Since they are globals, I don't have to worry about including it in all my other event sheets, but I can reuse them for different layouts.

    However, if I need an object to hold the variables, I've found a size zero array works well (set the Width to 0, leave Height and Depth at 1). I can give it instance variables for the globals, set it to persist, and I don't have to give it a space in the layout.

    I might have misunderstood you, though.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • PixelHero

    I like the idea of using the array. How do you add persist? You mean just global? You can't add behaviours to arrays.

    I've recently started using that first method, and I'd rather use global events as I feel it would make things easier for me in the long run, but without groups, it will turn into a massive list when I come to call them.

  • i know it isn't as organized as groups would be but you could do something like this IN_learning or PHY_Strength

    thats what i do and it helps and makes edits to related objects easy because they are all listed in order together

  • Perhaps you could use some global objects with instance variables to simulate grouping variables. For example a sprite called 'Intelligence' allows you to use Intelligence.Learning, Intelligence.Knowledge and Intelligence.Memory. A sprite called 'Physical' allows you to use Physical.Strength, Physical.Agility, Physical.Speed. Etc...

  • Ashley - Would a global array be better than a global sprite? I need to add sprites to layouts, and I'm wondering if I will need to have the sprite appear at least once, or every time I want to make a change, will I need the object to appear?

  • You don't need, make a new layout (normally the loading screen), leaving it with your sprites inside. One time created in the runtime, the object will remain available for you in every other layouts.

    As global objects, they can be placed outside the layout too, and you can disable the collision.

  • TELLES0808

    Does this mean the loading level (or level with the sprites in) needs to be accessed at least once for the sprites to be originally created?

    If that's the case, I won't be able to just open a random level and test it. This would mean that Global Events would be easier, and I could just put up with long lists :)

  • You need access the layout with the objects at least one time, to create them in runtime, because who will keep your variables alive is the instance of that object in the runtime.

    But don't worry, make invisible objects with 1 pixel of size, set the collision off (or not) and place them inside your start menu layout, or inside your level. One time created, they will remain active in any layout.

    Place them outside, or leave them inside, it really don't affect performance...

  • Yeah, just tested this, and I can't change local variables unless the sprite is on the screen.

    Also tried using an array instead of a sprite, and it works fine.

    Still, if it's possible in the future, I think it would be useful to be able to group global variables for those of us that plan on having dozens and dozens.

  • TELLES0808

    Sometimes when I test my game, I'll jump to certain points in the game. I'd rather not have to jump between each level each time.

    Thanks for your help!

  • Oh, that's the point, so, you can make an event sheet and call it as "shared sheet" or "debug sheet"... where you can place the actions to create the global objects anywhere you want, pre-configure them and them check if they already exist, skipping the step above.

    Should be something like this:

    = Intelligence.Count = 0

    -> Create Intelligence at X and Y;

    Import this event sheet inside any other event sheets you have...

    I personally like to organize my event sheets in separated parts, and import them all inside a global event sheet.

  • TELLES0808

    This works great with arrays rather than sprites, as you don't need to have them on any layout.

    Thanks to you and PixelHero

  • Very nice! indeed!!

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