Raised This Month: $ Target: $400
 0% 

Need help about exprresions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 07-21-2014 , 15:42   Need help about exprresions
Reply With Quote #1

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!
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********
Dark_Siders is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-21-2014 , 16:51   Re: Need help about exprresions
Reply With Quote #2

^ is the default escape character of pawn.
? and : are used for the short hand if-statement.
mottzi is offline
Send a message via MSN to mottzi
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-21-2014 , 17:25   Re: Need help about exprresions
Reply With Quote #3

Quote:
Originally Posted by mottzi View Post
^ 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.

Last edited by klippy; 07-21-2014 at 17:26.
klippy is offline
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 07-22-2014 , 06:59   Re: Need help about exprresions
Reply With Quote #4

Quote:
Originally Posted by mottzi View Post
? 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?
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********
Dark_Siders is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-22-2014 , 08:00   Re: Need help about exprresions
Reply With Quote #5

Quote:
Originally Posted by Dark_Siders View Post
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.
klippy is offline
Dark_Siders
Member
Join Date: Aug 2013
Location: Dreaming World
Old 07-22-2014 , 15:09   Re: Need help about exprresions
Reply With Quote #6

Thank you!
__________________
***********
I want to die peacefully in my sleep like my grandfather, not screaming in terror like his passengers.

***********
Dark_Siders is offline
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 07-22-2014 , 15:22   Re: Need help about exprresions
Reply With Quote #7

This:
PHP Code:
name[0] = '^0'
Same as this:
PHP Code:
name[0] = 0
Right?
Phant is offline
Send a message via ICQ to Phant
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-22-2014 , 18:54   Re: Need help about exprresions
Reply With Quote #8

Quote:
Originally Posted by Phant View Post
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.
klippy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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