HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

'is number even'

07-10-2007, 11:49 PM#1
fps-doug
hi guys um so Im making a map with a coordinate grid pathing system. You hit the arrow keys and you move left right up or down in squares at a time. it works fine, except I placed pillars are regular intervals (which of course you cant path on them). now i need a way to detect these pillars. Fortunately, each pillar is at a 'square' with even grid coordinates, for example, (2,2), (4,4), (8,4), etc.

In my trigger for movement, is there a way that I can create a condition "is number even" ? This would simplifie things greatly ( I could always do it manually number by number, but that might take awhile and I was wondering if there was a more efficient way).

Im doing everything in gui, but if the absolute only solution is jass then please feel free to explain it, ill try my best to learn it.
07-11-2007, 12:14 AM#2
Ammorth
Use modulo with your number and 2, if it returns 0 it is even, if it returns 1 it is odd.
07-11-2007, 12:16 AM#3
Dil999
I believe you could do this by simply making a real variable. From here, do an if comparison saying if the variable is equal to the variable converted to an integer then it will return true. Here is is in jass: (im not sure if my theory will work, though)
Collapse JASS:
function IsNumberEven takes nothing returns boolean
    if udg_Number == R2I(udg_Number) then 
        return true
    endif
endfunction
07-11-2007, 12:22 AM#4
maximilianx
Trigger:
If (all conditions are true) then do (then actions) else do (else actions)
Collapse If - Conditions
(Your_Integer mod 2) Not equal to 1
Collapse Then - Actions
The number is even
Collapse Else - Actions
The number is odd

simple GUI trigger to make it nice and easy.. X modulo 2 finds the remainder of X/2.. meaning if you get a 1 then it is an odd number. simple.

oh wait.. Ammorth beat me to the punch..
07-11-2007, 12:26 AM#5
fps-doug
well that was very simple, its just too bad I did not know to use modulo (not that I even knew what it was) :( thanks a bunch for the help.