Global/Local variables & Groups / Includes

  • I know what Global/Local variables, groups, and includes all generally do.

    However, could someone accurately summarize how the relationship between them is modified?

    For example; When and Why should I use a Local variable in a group in place of a global one? What things and differences can modify and pull from Local and Global variables respectively?

    Also, how do Includes modify potential changing of Global & Local variables if at all?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If a variable is only used in events from one group, you should consider moving this variable to this group. This helps to de-clutter your project. Local group variables are only accessible by events in this group.

    You should be aware, that local group variables are reset between calls. So it's not a good idea to put a variable like GameScore in a group, because it will reset to default value all the time.

    If you want your Local variable to keep its value, you need to change its type to Static. The problem with Static variables though is that if you need to reset them, you'll have to do it for each variable ("System Set GameScore to 0"). Unfortunately, there is no "Reset all static variables" action in C2.

    Same rules apply to local variable defined inside of events.

    As far as I know, "Include" does not have effect on Global variables. Global variable defined in one Event sheet is visible to the entire project, no matter if this event sheet is included into other event sheets or not.

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