Strange locals

0 favourites
  • 8 posts
From the Asset Store
"Easy Local Notifications" enhances games with customizable local notifications.
  • Hi! Maybe we need to submit this as a bug:

    If I define a local variable in ROOT of a group, but OUT of in-group events, then all inner events must see it's value, right?

    Otherwise, a variable defined INSIDE an event of a group must not be visible for other events (i.e. zero-valued), right?

    So why my variable, defined in root of group is reset to zero in every event?

    Does somebody knows? Is this okay?

    So if this is okay, we must be aware of using local variables, because we don't know exactly in which part of event-hierarhy it can be broken...

  • As I understand.. Local Variables reset every tick.

    So On any touch start and On any touch end are going to be on different ticks.. restarting to 0.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Um, its a bug that you can drag a local variable under a group.

    Ashley oops?

  • Local variables can be created/moved under groups, it's been like this. It's one way to manage global variable clutter.

    Klabundee has the right idea, local variables are reset every tick. If you have two separate events in the group, they can both access the group's local variables as long as it is on the same tick. I think another quirk is that triggers happen outside of a normal tick and won't be able to share data with normal events through a local variable, but can with a separate events using the same trigger.

  • That seems more like a nightmare to me. The scope is the group, reset every tick.

    If you move something in the group that references the local it would screw up a bunch of stuff.

  • I mean... moving stuff into and out of local variable scope is always fiddly, regardless of if it's in a group or not. FWIW you can't move an event that references a local variable to somewhere that local variable is not accessible, group or no group. And if you move the variable out, anything that references it locally gets deleted, with warning. This is consistent behavior wherever the local variable is.

  • Here is quote from manual:

    Local variables

    Local variables are variables placed nested under other events, or inside a group. They also show with a different icon to global variables.

    A local variable

    The main difference between global and local variables is local variables can only be accessed in their scope. A local variable's scope is its level of sub-events. All other events at the same level of indentation, or lower levels, can access the local variable. Events above it (less indented) cannot access the local variable.

    For example, if an event variable is in a group of events, it becomes a local variable. Then, it will only appear as an option for a variable in events inside that group. In other groups or in other event sheets it does not appear at all and cannot be accessed. This makes the variable local to the scope in which it is placed.

    Local variables convenient for temporarily holding variables over a short range of events, such as to calculate an average value (where a temporary sum variable may be necessary). It also helps keep the project simple, since it prevents the need to create more global variables, which appear everywhere in the project even if they are not needed everywhere.

    The scope of local variables is designed to mimic how the scope of variables works in real programming languages.

    ------------------------------------------------------------------------------

    Found in manual, page 115:

    Static

    Only applies to local variables. By default, local variables reset their value to the

    initial value every tick. However if Static is checked, the local variable's value will

    persist permanently, like a global variable. Static local variables differ from global

    variables in that they can still only be used within their scope. Global variables

    always hold their values permanently so the Static option does not apply to them.

    For more information about local variables, see Event Variables.

  • So moved them once again to the root of group but made them static. Now works.

    Non-Static variables in programming languages are reset every call of function, but not every tick, so that's why I missunderstood.

    Why do they need to be non-static by default? Is there so much profit?

    Thankyou guys for answers, you gave me right way to dig it out!

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