SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 18/07/2012, 08:22 AM   #11
Simon
Gangsta
 
Join Date: Jan 2006
Location: New Zealand
Posts: 514
Reputation: 56
Default Re: Today I learned - Share your newly found knowledge!

TIL a little trick to extend the amount of statements executed in ternary statements.

Never thought about using the ',' operator this way. Group of statements must be enclosed in brackets. It's a neat little trick that might create some interesting constructs:

pawn Code:
main () {
    new bool:cond = true;
    cond ? (print("T - First"), print("T - Second")) : (print("F - First"), print("F - Second"));

    print("SWITCHING TRUTH");

    cond = false;
    cond ? (print("T - First"), print("T - Second")) : (print("F - First"), print("F - Second"));
}
Simon is offline   Reply With Quote
Old 18/07/2012, 09:39 AM   #12
Night Dreamer
Big Clucker
 
Night Dreamer's Avatar
 
Join Date: Nov 2011
Posts: 39
Reputation: 0
Default Re: Today I learned - Share your newly found knowledge!

Today I learned more about bits
PHP Code:
const color = ((183)<<24|(115)<<16|(222)<<8); //purple!!!

GetPrintedRGB(color) return printf("Red: %d, Green: %d, Blue: %d", ((colorFrom >> 24) & 0xFF), ((colorFrom >> 16) & 0xFF), ((colorFrom >> 8) & 0xFF)); 
Night Dreamer is offline   Reply With Quote
Old 18/07/2012, 11:18 AM   #13
RebeloX
High-roller
 
RebeloX's Avatar
 
Join Date: Jul 2011
Location: Portugal
Posts: 2,257
Reputation: 442
Default Re: Today I learned - Share your newly found knowledge!

Today I learned how to use #error

pawn Code:
#if !defined MAX_SLOTS
    #error You must define the MAX_SLOTS in your script
#endif
__________________
RebeloX is offline   Reply With Quote
Old 18/07/2012, 01:34 PM   #14
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 3,062
Reputation: 694
Default Re: Today I learned - Share your newly found knowledge!

Today I learned that publics like OnPlayerText (in a filterscript) are still intact while the gamemode is restarting so you can, for example, actually still chat using Send(Player/Client)Message(ToAll)!
__________________

Sup?
RyDeR` is offline   Reply With Quote
Old 18/07/2012, 05:23 PM   #15
admantis
High-roller
 
Join Date: Sep 2009
Posts: 2,573
Reputation: 446
Default Re: Today I learned - Share your newly found knowledge!

Today I learned that filterscripts don't get reloaded when the servre is restarted, you have to reload the filterscripts manually.
__________________
Web developer for hire. Will make your website or your UCP for affordable rates!
admantis is offline   Reply With Quote
Old 19/07/2012, 11:27 AM   #16
EV007
Big Clucker
 
EV007's Avatar
 
Join Date: Jul 2012
Posts: 140
Reputation: 10
Default Re: Today I learned - Share your newly found knowledge!

Today I learned that I can use one line

pawn Code:
SetPlayerColor(playerid,(team[playerid] == team_one ) ? COLOR_RED : COLOR_BLUE );

instead of:

pawn Code:
if(team[playerid] == team_one)
{
SetPlayerColor(playerid,COLOR_RED);
}
if(team[playerid] == team_two)
{
SetPlayerColor(playerid,COLOR_BLUE);
}
EV007 is offline   Reply With Quote
Old 19/07/2012, 03:06 PM   #17
FireCat
High-roller
 
FireCat's Avatar
 
Join Date: Jul 2010
Posts: 2,403
Reputation: 596
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by EV007 View Post
Today I learned that I can use one line

pawn Code:
SetPlayerColor(playerid,(team[playerid] == team_one ) ? COLOR_RED : COLOR_BLUE );

instead of:

pawn Code:
if(team[playerid] == team_one)
{
SetPlayerColor(playerid,COLOR_RED);
}
if(team[playerid] == team_two)
{
SetPlayerColor(playerid,COLOR_BLUE);
}
Thats called the ternary operator
FireCat is offline   Reply With Quote
Old 19/07/2012, 06:45 PM   #18
JoBullet
Big Clucker
 
Join Date: Mar 2012
Posts: 59
Reputation: 100
Default Respuesta: Today I learned - Share your newly found knowledge!

Today I learned that returning array from function works in such a way that array's address is stored in a following address:
current function frame address + (argcount + 3) * sizeof(cell)
JoBullet is offline   Reply With Quote
Old 20/07/2012, 10:54 PM   #19
FireCat
High-roller
 
FireCat's Avatar
 
Join Date: Jul 2010
Posts: 2,403
Reputation: 596
Default Re: Today I learned - Share your newly found knowledge!

Today I learned you can do this:
pawn Code:
enum Something
{
 hi,
 bye
}

printf("%s",Something:hi);
FireCat is offline   Reply With Quote
Old 21/07/2012, 12:26 AM   #20
Littlehelper
Gangsta
 
Littlehelper's Avatar
 
Join Date: Nov 2011
Location: 420
Posts: 980
Reputation: 178
Default Re: Today I learned - Share your newly found knowledge!

Today I learned how to make my cat speak.
Jks, Today I learned why there were # tags being used in colors. (To Encode Them)
pawn Code:
"#COL_ORANGE"
Plus, i learned that pawn will not give error if the color is defined or not if you use hash tag in color.
Littlehelper is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Things you learned from GTA SA Toni Everything and Nothing 212 20/08/2011 07:07 AM
How you learned to script Bam23 Help Archive 9 11/04/2011 10:21 AM
What did u learned today ? rafay Everything and Nothing 170 30/03/2010 04:06 PM


All times are GMT. The time now is 09:14 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.