Local variables can't be changed

Bugs will be moved here once resolved.

Post » Fri Sep 23, 2011 3:17 am

[QUOTE=shinkan] "On start of layout" works for me to, but try to change it to every tick or every 1.0 sec... or add a Mouse: On Left button Clicked - > Add 1[/QUOTE]

Indeed, in r57 and using my previous capx, replacing the start of layout event, every tick and every X sec seem to just run once. The var gets set, but don't change afterwards.
Left click was already a known issue.

Same thing happens with a keyboard event.
Variable3 was created as a local variable in the group directly.

But in the end, isn't that the supposed behavior ?
I mean, each time the group gets called/executed, the local variable is "reset". If you want an increasing counter, have a local variable out of the scope of the group (a containing condition and/or group for example) or just a global variable.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Posts: 7,417
Reputation: 75,230

Post » Fri Sep 23, 2011 1:53 pm

I though it supposed to act like a Global Variable but in closed environment, in groups for example. So you could be able to do some stuff with it only in certain part of your code.
I asked about that cause i want to do a simple switch that exist in only one group and belongs to only one sprite. It could be easily done with instance variable or global variables, but well I just want to try local variables to see how they behave.
Besides I like the way they are not shown in the overall list, if you compare a system variable outside of that group. That makes things less confusing if you have loads of variables.

[quotes] But in the end, isn't that the supposed behavior?
I mean, each time the group gets called/executed, the local variable is "reset".[/quotes]
Posts: 2,611
Reputation: 36,844

Post » Fri Sep 23, 2011 2:28 pm

Kyatric is right, by design local variables reset every tick. They don't keep their value. Again, this is designed to mimic how local variables work in programming languages (you wouldn't expect a stack variable in C to have the same value last time the function was called). Global variables persist their value, of course, so maybe in this case you want a global variable. Remember, local variables are intended for when you temporarily need a place to hold a number over just a few events.
Scirra Founder
Posts: 25,207
Reputation: 200,355


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests