How do I Test an Array Value Added to a Global Variable

0 favourites
  • 4 posts
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.
  • Hi, I'm trying to do something that seems straightforward, but isn't working properly. Here is what is going on:

    "For each X element:

    If Array: Value at Array(x,y,z) = LocalVariable (it does)

    Trigger Once:

    -->And If Object.Var > or equal to (Array.at(x,y,z) + GlobalVariable) -->then ACTION: subtract (Array.at(x,y,z) + GlobalVariable) from Object.Var"

    (The Local and Global Variables have already been set, of course)

    For some reason, it's ignoring the "+GlobalVariable" part of the condition and action. It should be checking if the value in the array PLUS the GlobalVariable is greater than the Object.Var, and if so, subtracting all that from the Object.Var. Other than that, this event works well.

    Any ideas as to what I'm doing wrong? Can you not add variables to array values in conditions and actions? Is the Trigger Once messing it up? I need it to keep this event from continually subtracting the array value (+Global) from the Object.Var. Also, I don't think it matters, but the 'z' coordinate in the array is a variable, too.

    Thanks in advance...

  • Well, I've tried trigger once with this array loop:

    the counter just continuously went up, so I think there is a bug with that combination (or I understand the trigger once or loop incorrectly).

    You could try to work around it by either:

    a) use another global variable, instance variable or value in another object to basically save, whether this event already occured; set as condition occured = 0 and the loop afterwards and inside the event set occured = 1 somewhere

    b) pack it inside a function and call it when needed (my preference)

    Other than that comparing values in conditions should work flawlessly, at least I never experienced any problems there with expressions in brackets. Other problems could stem from comparing different types of objects (comparing strings with a number, or trying to add a number to a string).

  • Hi, thanks for the reply. I actually set the event up in a function right before you replied, which did eliminate the need for a Trigger Once condition. But it is still only subtracting the base value from the array and not adding the global. I can see the global value onscreen in a text object, so I know it is not being reset to 0 or anything.

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok, so I managed a workaround. I had to make a new local variable to store the base value from the array in an event placed just before the one in my 1st post. Then, I just replaced the "array.at" variables in the condition and action with this new local value which WILL add with the global variable.

    Is this a bug? The program doesn't have a problem getting the value from the array, but it won't add it to a global in an event. I have noticed that if I, say, have an similar array event, looking through all the x values, etc., and I want to create one object, it will create about 30 or so before moving on to the next event. It's almost as if there is a serious lag while it is searching the array (and I'm not talking about a big array), and if it finds the value, it keeps searching, but the condition has been satisfied so it gets stuck doing the action repeatedly until it is through searching for a while.

    I've just taught myself how to use this program in the last 4 months, so I don't really have a lot of programming knowledge to know what is going on. Maybe someone can shed a light on this.

    Thanks

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