Today I learned - Share your newly found knowledge!
#1

Yes, just like reddit.

Simple. If you learned something new related to SA-MP scripting, share it here!

Please:
  • Explain what it is you learned, don't just say you learned something. <----
  • Try keeping it concise.
  • Don't post stupid pictures or otherwise annoying, non-related stuff.
  • Don't link to or quote posts then say you learned that.
I'll start..


Today I learned the proper way to forward public functions is this:
pawn Code:
forward public OnSomethingHappen(a, b, c);
I've always done it without "public". The only difference, it seems, is it enforces some extra restrictions (such as not being able to assign default values).
Reply
#2

Today I learned that you can use a hash sign (#) instead of quote marks. E.G: SetPVarInt( playerid, #slice, 1 );
Reply
#3

Today I learned, that...
Quote:
Originally Posted by Mauzen
View Post
Converting variabes "downwards" isnt a big problem btw. Just use normal cells, and if it really depends on being just 1/2 bytes long, you could do this:
cell & 0x0000FFFF (2 byte/16 bit value)
cell & 0x000000FF (1 byte/8 bit value)
Reply
#4

Today I learned the compiler accepts trailing commas in enums.

pawn Code:
// Valid:
enum {
    ABC,
    DEF,
    GHI,
}
Reply
#5

Today I learned that color embeddings can be defined ontop of the script.

pawn Code:
#define BLUE_EMBED "{0000FF}"
 
 
SendClientMessage(playerid, -1, "White turns into"BLUE_EMBED" blue.");
Reply
#6

Today I learned that strcat is 2x more fast than format and with a simple definition you can make a new model of format.
Reply
#7

Today I learned that dialogs can be defined inside the enumerator

pawn Code:
enum {
    DIALOG_1,
    DIALOG_2
};
Reply
#8

Today I learned how to #emit
Reply
#9

Today i learned Enumerators (enums).
Reply
#10

Today I learned that OnGameModeExit is not being called when you shutdown the server console.
Reply
#11

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"));
}
Reply
#12

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)); 
Reply
#13

Today I learned how to use #error

pawn Code:
#if !defined MAX_SLOTS
    #error You must define the MAX_SLOTS in your script
#endif
Reply
#14

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)!
Reply
#15

Today I learned that filterscripts don't get reloaded when the servre is restarted, you have to reload the filterscripts manually.
Reply
#16

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);
}
Reply
#17

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
Reply
#18

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)
Reply
#19

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

printf("%s",Something:hi);
Reply
#20

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)