Any ways to make this shorter?
#1

How to make this line shorter:
pawn Код:
if(TeamMembers(teamid) > TeamMembers(T_RUSSIA) || TeamMembers(teamid) > TeamMembers(T_MEXICO) || TeamMembers(teamid) > TeamMembers(T_IRAQ))
I tried using parentheses but an error "tag mismatch" came up:
pawn Код:
if(TeamMembers(teamid) > (TeamMembers(T_RUSSIA) || TeamMembers(T_MEXICO) || TeamMembers(T_IRAQ)))
Reply
#2

Quote:
Originally Posted by Dan.
Посмотреть сообщение
How to make this line shorter:
pawn Код:
if(TeamMembers(teamid) > TeamMembers(T_RUSSIA) || TeamMembers(teamid) > TeamMembers(T_MEXICO) || TeamMembers(teamid) > TeamMembers(T_IRAQ))
I tried using parentheses but an error "tag mismatch" came up:
pawn Код:
if(TeamMembers(teamid) > (TeamMembers(T_RUSSIA) || TeamMembers(T_MEXICO) || TeamMembers(T_IRAQ)))
Why do you want to make that line shorter?
Reply
#3

Well I just thought there is a shorter way to do it, when I add even more teams it could get very long, but alright I'll use this then.
Reply
#4

you can try this:
pawn Код:
if(TeamMembers(teamid) > TeamMembers(T_RUSSIA)|TeamMembers(T_MEXICO)|TeamMembers(T_IRAQ))
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
No you can't - do you even know what that operator does? Did you TEST that code?
Exactly I don't think there is such an operator "|"

pawn Код:
|| // OR
&& // AND
Reply
#6

Quote:
Originally Posted by FalconX
Посмотреть сообщение
Exactly I don't think there is such an operator "|"

pawn Код:
|| // OR
&& // AND
Its bitwise or

@Dan.

You could use an loop if you got more teams
But for only three the normal if statement is enough
Reply
#7

oh, i see my mistake. i dont know why i assumed the values as bits, and accidently thought ahead w/o reading the variable names: teammemberS indeed implicits an integer, my wrong.

oh, yes, i tested it - but only with bits. when:
Код:
a=0xb1; b=0xb0; c=0xb1;
and the operator | ,aka "logical and", outputs a 1 if ANY of those bits equals 1, then
Код:
if (0 < a|b|c)
equals
Код:
if (0 < 1) //but equals 0 when a=0, b=0, c=0, 0and0and0=0...
while, with integers:
Код:
a=16; b=128; c=51;
a|b|c equals 16|128|51 //and HERE i stopped using my brain. i feel forced to explain my mistake...
Код:
a=0xb 00010000 //16
b=0xb 10000000 //128
c=0xb 00110011 //51
the fail output of my suggestion would have been
Код:
result=0xb 10110011 //179. this number appears from thin air, right? it doesnt:
^ thats 128+32+16+2+1=179, or 16+128+(51-16=35)=179.
the extra 35 is made of the differenting 3/4 bits in 51: 4 bits in 51 | 1 bit in 16, are adding 3 bits only:
Код:
(51-16=35) //equals
0xb 001 1 0011 //51
-
0xb 000 1 0000 //16
=
0xb 001 0 0011 //35
watch the missing bit #4 (valued 16), its gone!

i guess i will ask before i give rushed answers, especially when i dont get the problem right - sorry for causing confusion.

for those who didnt expect an excuse: its not my fault, its the integers'...

@******: "yes", and "yes". failed nevertheless. how/why? an honest answer would force you to censor it ^^
@FalconX: yes, this operator gets used in my fingerprint include/filterscript in my signature, its working excellent in the proper environment ^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)