How do I add another condition in this code?

Get help using Construct 2

Post » Thu Aug 11, 2016 5:11 pm

Hello,

i have this code https://s9.postimg.org/wrb4qrvgv/helppppp.png and I want to add another condition into it. If the frame is 1 change the frame to 0, it should work every 25 score as well. I tried it in different ways, but every time it gets stuck and it is not changing at all. :/

Appreciate every help! :)
B
10
S
1
Posts: 42
Reputation: 620

Post » Thu Aug 11, 2016 8:59 pm

Trigger once must be the last condition in the event, as documented in the manual and in the tooltip when you chose it as a condition.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Thu Aug 11, 2016 10:29 pm

Thanks for reminding me, but thats not the case in here... :/ I have 2 backgrounds and i want that the game will change background every 25th point, do you know ho to do it? :)
B
10
S
1
Posts: 42
Reputation: 620

Post » Thu Aug 11, 2016 11:38 pm

B
27
S
13
G
1
Posts: 130
Reputation: 3,058

Post » Fri Aug 12, 2016 9:40 am

takamoto solution is almost correct.
You indeed need to use subevents in which you check the animation frame number.
You also absolutely need an else for the second sub event.

Image
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,293

Post » Fri Aug 12, 2016 5:47 pm

Kyatric wrote:takamoto solution is almost correct.
You indeed need to use subevents in which you check the animation frame number.
You also absolutely need an else for the second sub event.

Image


why we have to use else?
B
27
S
13
G
1
Posts: 130
Reputation: 3,058

Post » Fri Aug 12, 2016 5:53 pm

Look at the code. If frame=0 -> set the frame to 1
Without the 'Else', event 5 will then checks if frame=1, which it does, because you just set it, so it sets it back to 0 again! 'Else' is critical to make sure only the one condition is checked at a time, and you don't flip-flop your values.
ImageImageImage
B
71
S
21
G
231
Posts: 3,691
Reputation: 129,358

Post » Fri Aug 12, 2016 9:18 pm

blackhornet wrote:Look at the code. If frame=0 -> set the frame to 1
Without the 'Else', event 5 will then checks if frame=1, which it does, because you just set it, so it sets it back to 0 again! 'Else' is critical to make sure only the one condition is checked at a time, and you don't flip-flop your values.


What about "trigger once"? We can use trigger once for both event 4 and 5.Then it changes the frame once.
B
27
S
13
G
1
Posts: 130
Reputation: 3,058

Post » Fri Aug 12, 2016 9:41 pm

Nope, same thing will happen.
ImageImageImage
B
71
S
21
G
231
Posts: 3,691
Reputation: 129,358

Post » Fri Aug 12, 2016 11:23 pm

takamoto wrote:
blackhornet wrote:Look at the code. If frame=0 -> set the frame to 1
Without the 'Else', event 5 will then checks if frame=1, which it does, because you just set it, so it sets it back to 0 again! 'Else' is critical to make sure only the one condition is checked at a time, and you don't flip-flop your values.


What about "trigger once"? We can use trigger once for both event 4 and 5.Then it changes the frame once.

The events are already triggered once because you put trigger once in the top event, but C2 reads events from top to bottom so it'll check if = 0 then set to 1 then check = 1 and it is cause last event set to 1
B
42
S
17
G
17
Posts: 2,247
Reputation: 17,461


Return to How do I....?

Who is online

Users browsing this forum: evillair, Yahoo [Bot] and 6 guests