What's this symbols ?
#1

":" "?"
pawn Код:
new a;
a = 1;
if(a == 1) : print("a == 1!") ? print("a == 0!");
Is this correct?

Whats ?, :, and
What's return 0x1 ? is return 1; ??
Reply
#2

? and : are triadic or ternary operators.
Clickety!

They're handy because you can use them in assignment (or pretty much any statement for that matter), for example:

PHP код:
new bool:false;
new 
= ( == false ) ? ( ) : ( ); 
b would be assigned 3, because a is evaluated as false, and it returns 3.

this could also be wrote out as:

PHP код:
new bool:false;
new 
b;
if( 
== false )
{
      
3;
}
else
{
      
2;

The code you posted:
PHP код:
new a;
1;
if(
== 1) : print("a == 1!") ? print("a == 0!"); 
Isn't correct, the correct way of writing it would be:

PHP код:
new a;
1;
print( ( 
== ) ? ( "a == 1!" ) : ( "a == 0!") ); 
As for 0x1 in the return, yea it's a hexadecimal representation of the value 1. See more about hex & pawn here:
https://sampwiki.blast.hk/wiki/Hex
Reply
#3

wiki is best
Reply
#4

THANKS alot !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)