# How to detect odd number?

Discussion in 'Triggers & Scripts' started by Garfield1337, Feb 16, 2010.

1. ### Garfield1337

Joined:
Jul 6, 2009
Messages:
1,806
Resources:
4
Maps:
1
Spells:
3
Resources:
4
Is it possible to detect if an integer variable is odd number?
Since i need to halve it and when it's number is odd,it's halves shouldn't be equal

2. ### meOme

Joined:
Jul 18, 2009
Messages:
272
Resources:
0
Resources:
0
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.

3. ### Pharaoh_

Joined:
Nov 6, 2008
Messages:
8,127
Resources:
11
Icons:
3
Skins:
1
Spells:
6
Tutorials:
1
Resources:
11
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.

4. ### Garfield1337

Joined:
Jul 6, 2009
Messages:
1,806
Resources:
4
Maps:
1
Spells:
3
Resources:
4
Well,thx for help
Rep for both

EDIT:
Lol,why would it return 0 for odd numbers? its obvious that 7 mod 3 = 1 (7 is odd number)