How many Global Variables is too much?

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.
  • In C2 you don't need to think about such aspects, as Ashley is the traditional programmer who takes care of all this (I hope he won't argue against it^^). In C2 gloval variables exist to keep data between layouts. So use them as you see fit. If you can manage a thousand globals - then use a thousand.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Contrary to (weirdly widespread) belief, number of layouts has NO effect on performance. Number of variables shouldn't either (unless you're up in the millions) but for the case you're talking about, you need to use a data structure such as webstorage or an array, just for convenience purposes.

  • Global variables have virtually no performance impact. The only limit on how many you can use is how far you can go before it becomes unmanageable. If you are using loads of variables you might want to switch to an array or dictionary instead, simply because they are more manageable.

  • number of layout or number of global variable have no impact on performance

    BUT its safe to use lowest number of it to keep your organisation

  • Depends on what your aiming for.

    JS v8 and all of the JIT have gotten pretty good. You could say unlimited. However there is a far better answer and a different way to look at the "how many globals is too many".

    The answer is.

    "Any more than what disrupts development, readibility and good development practices."

    After a certain point you will need to keep better track of these globals where you don't need to. Sounds easy. is easy. but it's still over all lost time.

    My personal global count max is 5.

    I keep variables in Groups to object them. Groups always define an ES.

    I also keep Dictionaries which store globals as an instance variable as Dictionaries are Global by nature.

    When I use a true global it's development value. Such as

    DebugLog string global. One where I will pop out a value to debug screen without the console window.

    as for storing player info such as best time.

    Dictionary.Add("BestTime_" & layoutname, timevariable)

    and there you go. 1 global dictionary. stores thousands of levels(no need for global vars). And best of all you can also do. WebStorage.Add( "BestTimeSave", Dictionay.asJson ). To save all the data for later. Then use

    Dictionary.FromJson( WebStoage.Get( "BestTimeSave"). boom smiple. only a few peice of code lines. and now you can support thousands of levels in only a few lines on a single ES.

  • I would like to put global variables into global objects (sprite or something else). It is more easier to access, and easy to copy to other project.

  • Personally, I'd love to see global variables get their own window, outside of the event sheets entirely, with additional support for sorting them into trees and branches. I usually end up putting all my global variables into a separate event sheet anyway, so they're out of the way (since they can't be put into groups), but then having to switch back and forth between that sheet becomes a bit of a chore. If we could have a window that can always be open, and easily arranged, that would save a whole lot of time.

  • Personally, I'd love to see global variables get their own window, outside of the event sheets entirely, with additional support for sorting them into trees and branches. I usually end up putting all my global variables into a separate event sheet anyway, so they're out of the way (since they can't be put into groups), but then having to switch back and forth between that sheet becomes a bit of a chore. If we could have a window that can always be open, and easily arranged, that would save a whole lot of time.

    Yeah, I do the same thing. This is definately a great suggestion. +100

  • Personally, I'd love to see global variables get their own window, outside of the event sheets entirely, with additional support for sorting them into trees and branches. I usually end up putting all my global variables into a separate event sheet anyway, so they're out of the way (since they can't be put into groups), but then having to switch back and forth between that sheet becomes a bit of a chore. If we could have a window that can always be open, and easily arranged, that would save a whole lot of time.

    +100 This would be awesome.

  • Personally, I'd love to see global variables get their own window, outside of the event sheets entirely, with additional support for sorting them into trees and branches. I usually end up putting all my global variables into a separate event sheet anyway, so they're out of the way (since they can't be put into groups), but then having to switch back and forth between that sheet becomes a bit of a chore. If we could have a window that can always be open, and easily arranged, that would save a whole lot of time.

    + 100 for organisation (and maybe to optimize and bug fix quickly and safely) ... like using groups / families

    + 0 for optimization / fsp / cpu memory render ...

  • matrixreal

    Yeah dude, an "Event Variables" panel in the engine would be awesome, it would have globals, locals, and any object's instance variables currently used in that particular event sheet, all nested into a branching tree format. Oh that would be so helpful! Great suggestion matrixreal!

  • You could even click on them in that event variables panel and it would take you to the spot in the event sheet where the global resides. Particularly helpful when working with local variables as it would take you to the folder that it's nested in and there you go! Your codes right there, man the more I think about this I really wish construct 2 would add this to their engine. Again matrixreal awesome idea!

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