Operator ':?' <-- - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Operator ':?' <-- (
/showthread.php?tid=447149)
Operator ':?' <-- -
sKgaL - 28.06.2013
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 :)
Re: Operator ':?' <-- -
Djole1337 - 28.06.2013
Dis guy bellow is right.
AW: Operator ':?' <-- -
BigETI - 28.06.2013
no need for ? and :
pawn Code:
StartRountCount = !StartRountCount;
is "Rount" even a word, or just a typo?
Re: Operator ':?' <-- -
sKgaL - 28.06.2013
I Didnt understand you.
Here is an exaple from operator ':?' :
Code:
format(str, 256, "Auto login [%s]", AutoLogin[playerid] ? ("On") : ("Off"));
Re: Operator ':?' <-- -
Jefff - 28.06.2013
pawn Code:
StartRountCount = (StartRountCount) ? false : true;
AW: Operator ':?' <-- -
BigETI - 28.06.2013
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.
Re: Operator ':?' <-- -
jamesbond007 - 28.06.2013
y u no read wiki..
https://sampwiki.blast.hk/wiki/Control_Structures#.3F:
Re: Operator ':?' <-- -
sKgaL - 29.06.2013
Thanks all for your help,
I really appreciate it.
Quote:
Originally Posted by Y_Less
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..
Re: Operator ':?' <-- -
sKgaL - 29.06.2013
Quote:
Originally Posted by Y_Less
|
Looks good,
Thanks Y_Less
AW: Re: Operator ':?' <-- -
BigETI - 29.06.2013
Quote:
Originally Posted by Y_Less
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
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!