AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need help about exprresions (https://forums.alliedmods.net/showthread.php?t=244650)

Dark_Siders 07-21-2014 15:42

Need help about exprresions
 
Hi guys!

I have question about some expressions in pawn.

What are these expressions?

Code:

^, ?, :
example of "?" and ":" :

Code:

random_num(0, 1) ? 1.0 : -1.0
And please give examples about usage of "^".

Please help me!

mottzi 07-21-2014 16:51

Re: Need help about exprresions
 
^ is the default escape character of pawn.
? and : are used for the short hand if-statement.

klippy 07-21-2014 17:25

Re: Need help about exprresions
 
Quote:

Originally Posted by mottzi (Post 2171548)
^ is the default escape character of pawn.
? and : are used for the short hand if-statement.

Well he asked about expressions, not characters, so ^ in this case would be bitwise XOR operator.
And examples... can't think of any right now, but I know some people are using it in encoding their strings for some security reason.

Dark_Siders 07-22-2014 06:59

Re: Need help about exprresions
 
Quote:

Originally Posted by mottzi (Post 2171548)
? and : are used for the short hand if-statement.

Can you explain more? how to use them?


about "^":

for example:
Code:

name[0] = '^0'
and some where they use this in ^" ^" format

I want to know what this do actually?

klippy 07-22-2014 08:00

Re: Need help about exprresions
 
Quote:

Originally Posted by Dark_Siders (Post 2171789)
Can you explain more? how to use them?


about "^":

for example:
Code:

name[0] = '^0'
and some where they use this in ^" ^" format

I want to know what this do actually?

That "Short hand if-statement" is actually called "Ternary operator", but the name he provided is an excellent description for that operator. So, if you have something like this:
PHP Code:

if(boolean)
       
number 5;
else
       
number 10

you can shorten it to:
PHP Code:

number boolean 10

I hope you can see relation between these two. :)

And for this:
PHP Code:

name[0] = '^0'

'^0' means that character is 0 (see ASCII table for more information).
So, these four are exactly the same:
PHP Code:

character 'A';
character 65;
character '^65'// Although not sure about this one
character '^0x41'

And you can also use that in strings, so
PHP Code:

string[] = "H^0x65llo"

Which matches "Hello", because hex value of character 'e' in ASCII table is 0x65.
And ^" ^" format as you call it are escaped quotes. You must use escaped quotes if you use multiple quotes in your string, telling the compiler that quote in your string is not closing quote for your string, but rather just a quote character inside it. Example:
PHP Code:

string[] = "My name is ^"KliPPy^""

Ingame, this will display
Code:

My name is "KliPPy"
If you used normal quotes just like:
PHP Code:

string[] = "My name is "KliPPy""

the compiler would throw an error, because he would think that the string is equal to "My name is " and all after it is just some crap which should not be there.

Dark_Siders 07-22-2014 15:09

Re: Need help about exprresions
 
Thank you!:)

Phant 07-22-2014 15:22

Re: Need help about exprresions
 
This:
PHP Code:

name[0] = '^0'

Same as this:
PHP Code:

name[0] = 0

Right?

klippy 07-22-2014 18:54

Re: Need help about exprresions
 
Quote:

Originally Posted by Phant (Post 2172001)
This:
PHP Code:

name[0] = '^0'

Same as this:
PHP Code:

name[0] = 0

Right?

Right, it is the same thing that I have wrote in my last post, in PHP tag number 4.


All times are GMT -4. The time now is 13:13.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.