How do I reference odd or even numbers?

Get help using Construct 2

Post » Tue Feb 28, 2017 6:55 pm

I currently have a line that works perfectly for a similar need that reads:
sprite animation frame > 0

I need to change it to something like:
sprite animation frame = (odd or even numbers)

I thought this would work but it doesn't seem to:
sprite animation frame = 1|3|5|7|9|11
I need it to trigger when ANY one of these odd frames are active. I think what is happening is it is returning a 1 or a 0, so in effect I am saying that if the animation frame is any one of these odd numbers then the animation frame =1. I need it to to trigger on something like animation frame=7.

Or maybe I am approaching it all wrong.
B
42
S
20
G
6
Posts: 106
Reputation: 6,567

Post » Tue Feb 28, 2017 7:15 pm

sprite animation frame % 0 will equal 0 if even, 1 if odd.
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Wed Mar 01, 2017 7:03 pm

sprite animation frame % 0 will equal 0 if even, 1 if odd.

I'm not sure what the "%" is telling me.


sprite animation frame = 1|3|5|7|9|11

In the above example, if the active frame is odd and it returns a result of 1(being true), does "sprite animation frame = xx" ultimately become:
sprite animation frame = 1
and if even(false):
sprite animation frame = 0

Is this correct?
B
42
S
20
G
6
Posts: 106
Reputation: 6,567

Post » Wed Mar 01, 2017 7:10 pm

if Sprite.AnimationFrame % 0 = 0 -> do even code
else -> do odd code
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Wed Mar 01, 2017 7:12 pm

Pick the sprite
System compare two values ... sprite animation frame % 0 = 1
_____________ actions run if sprite animation frame = odd

Does the same, just more simple

% means modulo, or 'remainder after division', it is an operator like + - / *

say .. 5 % 3 ....>... 3 goes 1 time in 5 with a remainder of 2
so .... 5 % 3 = 2

edit, i see you got an answer, i post anyway
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Mar 03, 2017 2:26 am

Thank you very much
B
42
S
20
G
6
Posts: 106
Reputation: 6,567


Return to How do I....?

Who is online

Users browsing this forum: irina and 10 guests