Testing if number is odd or even

0 favourites
  • 5 posts
From the Asset Store
Jump on numbers in the proper order and reach the sun!
  • 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!

  • 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....

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • 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 ! <img src="smileys/smiley11.gif" border="0" align="middle" />

  • Thanks! Solved

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