Local variables can't be changed

0 favourites
  • 12 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • It seems that once Global variable is turned into a local variable - by dragging it inside the group in my case, can be set only once.

    You can't add, substract, or set that local value later in runtime. If you set it like ie. "Local number Variable = 0" it stays 0.

    It happens on Win 7 64bit, C2 r57. Not sure about previous releasses.

  • Can you post a .capx? Was working OK last I checked.

  • I't happening with every new project. Create a global variable move it to a group an try to add, substract or set that variable to something different.

  • Sorry shinkan, I tested what you say, and it works as intended (I can change, add, substract to the value). Tested in XP sp3

  • can you do a quick capx file and post it?

  • "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

  • All those work for me as well, shinkan! Can't reproduce any issue.

  • hmm ok. to be sure, step by step

    • New project
    • add text object
    • add mouse object
    • create Global Variable = 0
    • create Group
    • move Global Variable into the Group - it's now Local Variable = 0
    • Every tick set text to Local Variable
    • on left click add 1 to Local Variable

    after previewing this layout text object shows 0 - thats correct, but clicking mouse buttons doesnt do anything.

    I did that with keybord object too and with Every xx seconds and still Text object displays Local Variable initial value 0.

    :/

    I've also add another sprite to see maybe text object is not displaying it properly.

    if local variable = 0 - set sprite opacity to 100

    if local variable = 1 - set sprite opacity to 50

    Nothing happens. Local Variable stays at 0, sprite stays with 100 opacity.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • "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

    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.

    glob2loc_var2.capx

    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.

  • 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]

  • 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.

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