For Each Loop not respecting global variable

Get help using Construct 2

Post » Sat Dec 22, 2012 12:30 pm


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

B
8
S
2
G
1
Posts: 21
Reputation: 1,492

Post » Sat Dec 22, 2012 12:35 pm

You should be checking if BABY_HAPPY = "1" since it's a text var not a number.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sat Dec 22, 2012 12:38 pm

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))
newt2012-12-22 12:43:02
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat Dec 22, 2012 12:58 pm


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
B
8
S
2
G
1
Posts: 21
Reputation: 1,492

Post » Sat Dec 22, 2012 1:06 pm

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
B
8
S
2
G
1
Posts: 21
Reputation: 1,492

Post » Sat Dec 22, 2012 2:53 pm

I don't see where you had it picking them randomly in the initial code.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767


Return to How do I....?

Who is online

Users browsing this forum: abdalghani, Kagubro and 22 guests