For Each Loop not respecting global variable

0 favourites
  • 6 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 have a little frustrating problem. I have a character (baby01) that has 3 animation states, idle, sad and happy. Each state plays through a random selection of animations.

    My issue is that when I compare the value of one of my boolean(0/1 text) states the actions do not happen. I've tried using local and global variables, moving the compare to different parts of the 'for each' loop but nothing helps.

    Below is the code I have created, as you can see my globals are at the top, at the moment I am setting baby_happy to 1 manually just to test, then in the code I say if baby_happy is equal to 1 play the animations.

    (everything works if I remove the compare variable check but I need it to change animation states.

    Any idea what I am doing wrong here?

    Thanks

    Simon

    <img src="https://dl.dropbox.com/u/3796932/global_Check.jpg" border="0" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You should be checking if BABY_HAPPY = "1" since it's a text var not a number.

  • Um, how about taking out the for each?

    You don't need it here as the variable comparison picks those instances.

    Also you dont need to use a global in a string if you just concatenate the animation name with the random number. "idle"&int(random(3))

  • Thanks for the quick replies.

    Good spot Ramones, I am now kicking myself over that :)

    Newt, I wanted all my 'babies' to be doing different things and thought that if it wasn't in a for each loop then they'd all do the same thing. I've just tested it without the for each and sure enough they are still doing their different motions. Thank you for the advice!

    Simon

  • Update...

    Upon removing the for each loop, the code that randomly mirrors the sprites causes all of the sprites to mirror at the same time, I was wanting them to individually mirror at different intervals which is what I had with the for each loop.

    Shall I put the for each back in, or is there a different/better way to do it?

    Thanks

    Simon

  • I don't see where you had it picking them randomly in the initial code.

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