PDA

View Full Version : MOD to Pawn


SumX
19/08/2015, 11:12 PM
Hello!
I want to check if a number is even or uneven.
For those who don't understand: 1 - uneven, 2 - even, 3 - uneven ... etc.

In c++ I am doing this at school by using this:
if(x%2)
if(x%2 == 0)

how can I do this in PAWN?

Abagail
19/08/2015, 11:20 PM
Do they teach you how to use the search function at school aswell? If not, I think it'd be great if you got that class, because you apparently need it sir.
http://forum.sa-mp.com/showthread.php?t=70747

SumX
19/08/2015, 11:22 PM
I searched only for MOD samp on ******. thank you!

Alex Magaņa
19/08/2015, 11:31 PM
I searched on samp wiki and this is the only way i found but the script will look a mess xd:
http://wiki.sa-mp.com/wiki/Control_Structures#else
With ELSE & IF.

Nero_3D
19/08/2015, 11:57 PM
Just use that instead of MOD
#define IsOdd(%0) (%0 & 1)

Crayder
20/08/2015, 12:00 AM
Just use that instead of MOD
#define IsOdd(%0) (%0 & 1)This, with this for even: #define IsEven(%0) (!IsOdd(%0))
if(x%2)
if(x%2 == 0)Those should work too, but binary (thus, the binary AND above) is better.

Mauzen
20/08/2015, 12:01 AM
Just use that instead of MOD
#define IsOdd(%0) (%0 & 1)

FIY this checks if the last bit is set, so if the binary numbers contains a 1. A clever method, dont think the compiler optimizes this by itself.