Testing if number is odd or even

Get help using Construct 2

Post » Mon Feb 04, 2013 6:40 pm

Hi everyone im new to C2. I bought the personal edition a few days ago and im loving it. I have experience in html, javascript/ajax and php.. and what im asking is really simple but i cant figure out how to do it in C2.

How can i do something like this:

if(value%2 == 0){
//something happens here
}else{
//something else happens here
}

Thanks in advance!
B
3
Posts: 2
Reputation: 279

Post » Mon Feb 04, 2013 7:40 pm

This probably isn't the most efficient way but you could test whether the integer of the number divided by 2 and than multiplied by 2 is equal to the number...

if   int(n/2)*2 = n
else....BenGIJOE2013-02-04 19:41:06
B
5
S
1
G
1
Posts: 12
Reputation: 899

Post » Mon Feb 04, 2013 7:43 pm

You can do it exactly how you posted in your thread.

use the System compare two values and use:

First Value : VARIABLE % 2
Comparision : = Equals to
Second Value : 0

and put in your actions for your even event.

After this click on the Event you just created and hit X to add an ELSE statement

B
16
S
4
G
4
Posts: 23
Reputation: 3,937

Post » Mon Feb 04, 2013 7:45 pm

Actually, the % operator exists in the C2 syntax. Use the "Compare two values" from the System object, and an else statement after if need be.

edit: ninja'ed ! Magistross2013-02-04 19:46:46
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Mon Feb 04, 2013 7:59 pm

Thanks! Solved
B
3
Posts: 2
Reputation: 279


Return to How do I....?

Who is online

Users browsing this forum: Rezzon71, theosciandra and 23 guests