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

Today I learned that the bone structure of skin Id 267 Officer Jimmy Hernandez Is fucked up.
Reply
#22

Today I learned that the name of an enum also defines its total size.
Reply
#23

Quote:
Originally Posted by Vince
View Post
Today I learned that the name of an enum also defines its total size.
Only if you use the default increment (+= 1)

Today I learned that NOP's are slower than no code
Reply
#24

Today i learnt that you can use 0 < Var < 5 instead of Var > 0 && Var < 5
<meh was so ez>
Reply
#25

Today I learned how to use the '%' operator!
It gives you the rest of a division, for example:
pawn Code:
9 / 4 // This will give you 2
9 % 4 // This will give you 1
Reply
#26

The '%'(modulus) operator returns remainder of division.
Reply
#27

Quote:
Originally Posted by Niko_boy
View Post
Today i learnt that you can use 0 < Var < 5 instead of Var > 0 && Var < 5
<meh was so ez>
I studied that way of writing (x < y < z means y is between x and z) at school, but I discovered that you can use it in Pawn and in some other languages very recently.
Reply
#28

Today I learned getdate(&year=0, &month=0, &day=0) returns the current day of the year (i.e. 5th of febuary is the 36th day).
Reply
#29

Today I learned ;
pawn Code:
new Float:vec[3]; GetPlayerPos(playerid,vec[0],vec[1],vec[2]);
instead of
pawn Code:
new Float:X, Float:Y, Float:Z; GetPlayerPos(playerid,X,Y,Z);
Reply
#30

Today I learned because of compiler bug, you can place entries in the public functions table by doing this:
pawn Code:
forward public SomeFunction();
SomeFunction(){}
Not one extra instruction of code will be inside the AMX.
Reply
#31

Today i learned how to use Stocks.

pawn Код:
stock KillPlayer(playerid)
{
    SetPlayerHealth(playerid, 0.0);
    return 1;
}
just a gay example
PS: had to go that's why didnt added how to use it in Command :S
Reply
#32

Today I learned that this is how you enforce someone implementing function(not public) to return array of exact size:

Код:
forward [128] getMessage(playerid);

stock getMessage(playerid)
{
    #pragma unused playerid
    new msg[128];
    return msg;
}
Of course those work for multiple dimensions too.

Код:
forward [128][1][2] getInfo();

stock getInfo()
{
    new info[128][1][2];
    info[0][0][1] = 1;
    return info;
}
This also works for natives:
Код:
native [128] getClientMessage(playerid);
Reply
#33

Today I learnt (or more realised) how to pass indeterminate sized arrays to functions:

pawn Код:
stock CreateVehicleSpawn(someArray[], someArray_size = sizeof(someArray))
{
    // blah
}
because doing this will produce an error:

pawn Код:
stock CreateVehicleSpawn(someArray[])
{
    printf("Array size: %i", sizeof(someArray));
}
'indeterminate array size in sizeof expression'
Reply
#34

Today I learned how to make a simple teleport command.

Quote:

if (strcmp("/lv", cmdtext, true, 10) == 0)
{
SetPlayerPos (playerid, 2002.1925,1543.9114,13.5859);
SetPlayerInterior (playerid, 0);
SendClientMessage (playerid, 0xaa3333a, "Welcome to Las Venturas.");
SendClientMessage (playerid, 0xFFFFFFF, "This area is free to map!");
return 1;
}

if (strcmp("/lvair", cmdtext, true, 10) == 0)
{
SetPlayerPos (playerid, 1592.0784,1171.6952,14.2241);
SetPlayerInterior (playerid, 0);
SendClientMessage (playerid, 0xaa3333a, "Welcome to Las Venturas Airport.");
SendClientMessage (playerid, 0xFFFFFFF, "This area is free to map!");
return 1;
}

if (strcmp("/sfair", cmdtext, true, 10) == 0)
{
SetPlayerPos (playerid, -1161.7926,33.5112,14.1484);
SetPlayerInterior (playerid, 0);
SendClientMessage (playerid, 0xaa33331, "Welcome to San Fierro Airport.");
SendClientMessage (playerid, 0xFFFFFFF, "This area is free to map!");
return 1;
}

if (strcmp("/home", cmdtext, true, 10) == 0)
{
SetPlayerPos (playerid, -49.6428,-270.6409,6.6332);
SetPlayerInterior (playerid, 0);
SendClientMessage (playerid, 0xaa33331, "Welcome to Home. The place you spawned.");
SendClientMessage (playerid, 0xFFFFFFF, "This area is free to map!");
return 1;
}
return 0;

Reply
#35

Today I learned that only class-specifiers('stock','const','static','public') that cannot mix together are 'public' and 'static', thus following are all correct in any combination(Note: only one class-specifier can be defined for one declarator)
Код:
new stock const static variable;
new stock const public variable;
new stock const const static variable; // error, 'const' class-specifier defined twice for one declarator.
Today I learned that you can set native's index arbitrarily like this
Код:
native func() = -0;
This will produce following(in assembly code):
Код:
sysreq.c 0
Note that integer following equal-sign must be negative,
This is invalid:
Код:
native func() = 11; // error
Another valid example:
Код:
native func() = -123;
The native's index would now be -123
Reply
#36

Today I learned that the compiler implicitly includes default.inc in all scripts.
Reply
#37

Today I learned that there exists a keyword named "defined", its design is very much same as sizeof though its functionality is similar to "#if defined" pre-processor construct. "defined" keyword resolves at compile-time to constant-expression(in this case bool: tagged). Its functionality is to deduce existance of either local or global variable, function, state variable or macro.
Syntax: (parentheses are optional)
Код:
if(defined symbol)
{}
if(defined(symbol))
{}
new const symbol_exists = defined(symbol);
Reply
#38

Today I learned that using static to initialize variable inside a loop is much more efficient than using new.
Reply
#39

Quote:
Originally Posted by Arca
Посмотреть сообщение
Today I learned that using static to initialize variable inside a loop is much more efficient than using new.
That's untrue, static variable is a global with a visibility limited to a function within it's declared, and it has nothing to do with efficiency, put it another way:
This code:
Код:
new static variable;
is equivalent to this code:
Код:
static variable;
Reply
#40

Today I learned that pattern name is called prefix. The prefix is the part of pattern that begins at the beginning of the pattern and ends on first occurrence of non-alphabetic character.
Note: in this context alphabetic means it is member of: 'a'..'z', 'A'..'Z', '0'..'9', '@', '_'.
This is important because warning 201("redefinition of constant/macro") is issued when there are more then one equivalent PREFIXes(NOT patterns).
Код:
#define pattern substitution
#define prefix<non-alphabetic substitution
#define prefix{non-alphabetic warning 201 issued
I have also learned that trailing argument in pattern is cut off if it exists because it could match anything,
Код:
#define _X%1 whatever
actually is equivalent to
Код:
#define _X whatever
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)