• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How to detect odd number?

Status
Not open for further replies.
Level 7
Joined
Jul 18, 2009
Messages
272
Use the modulo-function in your condition (under Integer Comparison --> Math - Modulo).

Modulo returns the rest of a division (for example "7 mod 3 = 1").
So "x mod 2" will return 0 for an even number and 1 for an odd number.
 
Try this:
  • Odd or Even
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set Integer = (Integer + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Integer mod 2) Equal to 0
        • Then - Actions
          • Game - Display to (All players) the text: ((String(Integer)) + = odd)
        • Else - Actions
          • Game - Display to (All players) the text: ((String(Integer)) + = even)
Edit1: AAAAAAAAAAAAAAAA way too late :(

Edit2: Actually meOme, 0 will return for the odd number, not the even one.
 
Status
Not open for further replies.
Top