Operator ':?' <--
#1

How do I use operator ':?' ?
Lets say I have this code :

Code:
if(StartRountCount)StartRountCount=false;
else StartRountCount=true;
How can I short it using ':?' ?
Thanks alot :)
Reply
#2

Dis guy bellow is right.
Reply
#3

no need for ? and :
pawn Code:
StartRountCount = !StartRountCount;
is "Rount" even a word, or just a typo?
Reply
#4

I Didnt understand you.

Here is an exaple from operator ':?' :
Code:
format(str, 256, "Auto login [%s]", AutoLogin[playerid] ? ("On") : ("Off"));
Reply
#5

pawn Code:
StartRountCount = (StartRountCount) ? false : true;
Reply
#6

Do you really want something like
pawn Code:
StartRountCount = StartRountCount ? false : true;
this?

My example above
pawn Code:
StartRountCount = !StartRountCount;
is in my opinion much more efficient.
Reply
#7

y u no read wiki..

https://sampwiki.blast.hk/wiki/Control_Structures#.3F:
Reply
#8

Thanks all for your help,
I really appreciate it.

Quote:
Originally Posted by Y_Less
View Post
Better question, why? You clearly have code that works, shortening it will not make it "more efficient" (whatever people think that means) and will just make the code harder to read.
I wanted to expend my pawn skills..
Reply
#9

Quote:
Originally Posted by Y_Less
View Post
In that case read the language guide:

https://sampforum.blast.hk/showthread.php?tid=289258
Looks good,
Thanks Y_Less
Reply
#10

Quote:
Originally Posted by Y_Less
View Post
Better question, why? You clearly have code that works, shortening it will not make it "more efficient" (whatever people think that means) and will just make the code harder to read.
Have you tested it yet? I had faster results on
pawn Code:
toggle = !toggle;
than on
pawn Code:
toggle = toggle ? false : true;
to be excact:
Code:
[02:45:40]  Starting benchmark test with 3 tests each method with 1000000 loops...
[02:45:40]  Toggler - "ternary operator" the 1.
[02:45:40]  1. result of ternary operator toggling: 99 ms
[02:45:40]  Toggler - "ternary operator" the 2.
[02:45:41]  2. result of ternary operator toggling: 99 ms
[02:45:41]  Toggler - "ternary operator" the 3.
[02:45:41]  3. result of ternary operator toggling: 99 ms
[02:45:41]  Toggler - "equals not" the 1.
[02:45:41]  1. result of equals not toggling: 84 ms
[02:45:41]  Toggler - "equals not" the 2.
[02:45:41]  2. result of equals not toggling: 84 ms
[02:45:41]  Toggler - "equals not" the 3.
[02:45:41]  3. result of equals not toggling: 84 ms
[02:45:41]  Benchmark test finished!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)