Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by Abagail
View Post
Today I learned Y_Less is not in-fact a robot. Put this in your signature if you thought he was a robot!

NOTICE: Please don't give me an infraction for this! Cheers!
Quote:

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.
OT :

Today I learned that getting player's weapon or the weapon data completely won't work very well under OnPlayerSpawn.
pawn Code:
new
    pwdata[MAX_PLAYERS][13][2];

public OnPlayerSpawn(playerid)
{
    for(new i; i< 13; i++)
    {
        GetPlayerWeaponData(playerid, pwdata[playerid][i][0], pwdata[playerid][i][1]);
    }
    return 1;
}
This won't work because GetPlayerWeaponData is called before giving the weapons which is provided by class. Or even if GivePlayerWeapon is called under OnPlayerSpawn, it wouldn't work either. It might work at some cases, but not always as I've got some experience in regarding it yesterday. The better way to retrieve weapon data is by delaying them by running a timer.

pawn Code:
new
    pwdata[MAX_PLAYERS][13][2];

public OnPlayerSpawn(playerid)
{
    SetTimerEx("getwepdata", 1000, false, "d", playerid);
    //Interval could be lowered, but I'm just ensuring that things are clear.
    return 1;
}

forward getwepdata(playerid);

public getwepdata(playerid)
{
    for(new i; i< 13; i++)
    {
        GetPlayerWeaponData(playerid, pwdata[playerid][i][0], pwdata[playerid][i][1]);
    }
    return 1;
}
Reply

Quote:
Originally Posted by Y_Less
View Post
No, the correct term is "cyborg".
Actually cyborg is short for "cybernetic organism", which is the correct term.
Reply

Today I learned :
  • It's was possible to create a files.txt where all textdraw will be saved and It's will load all textdraws like an include to avoid spamming my gamemode with textdraw line.
pawn Code:
public OnGameModeInit()
{
    // pawn_code
    #include <dm2fou\interface_textdraw.txt>
    return 1;
}
Code:
in interface_textdraw.txt

Interface1 = TextDrawCreate(595.599975, 412.166687, "usebox");
TextDrawLetterSize(Interface1, 0.000000, 0.761847);
TextDrawTextSize(Interface1, 464.399993, 0.000000);
TextDrawAlignment(Interface1, 1);
TextDrawColor(Interface1, 0);
TextDrawUseBox(Interface1, true);
TextDrawBoxColor(Interface1, 102);
TextDrawSetShadow(Interface1, 0);
TextDrawSetOutline(Interface1, 0);
TextDrawFont(Interface1, 0);
Reply

Today I learned How to make derby , fallout.
Reply

Today i learned and I tested that its more effective use multiple timers with light tasks than a few with heavy tasks. (ty [HLF]Southclaw)

My server stop giving me packetloss
Reply

Today I got bitten by bits and tags:
pawn Код:
bool:Anything() {
    return bool:32;
}
It still will hold value of 32 (even though you won't encounter any problems with tag mismatch, as it still is logically truthy and falsy). If you want to be 100% certain that your bool is real bool with {0, 1} values, better do double-negation
pawn Код:
bool:Anything() {
    return !!32;
}
Reply

Well, to be honest I always check for truthy values (in pawn, js/php is another pair of boots). But it's partially your fault (not really)! I always check API first
Quote:

<summary>Group_GetPlayer</summary>
<param name="Group:g">Group to check.</param>
<param name="p">Player to check.</param>
<returns>
Is this player in this group?
</returns>

And I for some reason (premature microoptimising Pcode size I guess) did
pawn Код:
if(Group_GetPlayer(Users, pid) == Group_GetPlayer(Admins, pid))
instead of &&
Reply

I'm not sure if the terms "truthy" and "falsey" really exist in Pawn. False is 0, and true is not false.

Truthy/falsey refers to values in languages such as JavaScript where the following are treated as false in an if-statement:
Код:
""
NaN
null
undefined
0
Reply

Quote:
Originally Posted by Slice
Посмотреть сообщение
I'm not sure if the terms "truthy" and "falsey" really exist in Pawn. False is 0, and true is not false.

Truthy/falsey refers to values in languages such as JavaScript where the following are treated as false in an if-statement:
Код:
""
NaN
null
undefined
0
So....

Код:
0 = false
1 = true
2 = true 
...
36 = true
Or am I not understanding you correctly?
Reply

Just to be clear - '\0'/EOS is exactly the same as 0, and is simply used for being more meaningful in context of strings?
Reply

True. Pun intended.
Reply

What is the purpose of making this macro? There's still a "stock" declaration before the macro.
Reply

Today I learned a different way to check for -1!

These two if-statements check for the same thing:
pawn Код:
if (strfind("hello world", "hello") != -1) {
    printf("string found!");
}

if (~strfind("hello world", "hello")) {
    printf("string found!");
}
How does this work?

~ is bitwise NOT, meaning every bit of the number will get flipped around.
0xFFFFFFFF is the same as -1, which is the same as 0b11111111111111111111111111111111. It is the only number with all bits set to 1.
What happens when you flip all 1? They will all become 0! If the number is anything else, it will contain at least one 1 after being flipped. As we all know, any number that is not 0 is true in an if-statement.
Reply

Quote:
Originally Posted by Slice
Посмотреть сообщение
Today I learned a different way to check for -1!

These two if-statements check for the same thing:
pawn Код:
if (strfind("hello world", "hello") != -1) {
    printf("string found!");
}

if (~strfind("hello world", "hello")) {
    printf("string found!");
}
How does this work?

~ is bitwise NOT, meaning every bit of the number will get flipped around.
0xFFFFFFFF is the same as -1, which is the same as 0b11111111111111111111111111111111. It is the only number with all bits set to 1.
What happens when you flip all 1? They will all become 0! If the number is anything else, it will contain at least one 1 after being flipped. As we all know, any number that is not 0 is true in an if-statement.
Okay that is really impressive. Where did you learn bit operators (if they are called like that, I'm not quite sure) ?
Reply

Quote:
Originally Posted by dominik523
Посмотреть сообщение
Okay that is really impressive. Where did you learn bit operators (if they are called like that, I'm not quite sure) ?
They are everywhere. The tilde is a bitwise complement (aka NOT). You can learn about them in like all C* languages (and other languages, just using C as an example). http://www.cprogramming.com/tutorial...operators.html
Reply

Quote:
Originally Posted by Write
Посмотреть сообщение
Today I learned that you can enlarge arrays to a dull of 99kb and 56ds without encountering any sort of problem in the process.
You mean 56 dimensions?
Even with the minimum of just 2 fields per dimension this would make the array 288230376151711744 bytes in size. Thats 268,435,456 GB or 256 PB, roughly 2 hours worth of the global internet traffic. Somehow I doubt that the samp server would start without problems with an array like that loaded, the worlds strongest supercomputer couldnt even fit 0.5% of that in its ram.
Reply

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
Today I found out that NetStats_GetConnectedTime() doesn't reset when you use "gmx"
Players never actually disconnect when you gmx. The disconnect callback is called so players stats and script stuff is not lost in the process because gmx is not actually a restart command. Gmx is "gamemode exit," it exits the current gamemode and advances to the next in the list of gamemodes in your server.cfg file. If you only have gamemode 0, then it will exit and init the one gamemode you have. This is why all players are actually connected in OnGameModeInit, thus you can detect gmx and prevent RemoveBuildingForPlayer crashes.
Reply

If u use \ in the last of a line starting with // ,u will get errors as shit,lol it took alone time to find this shitty erros xD
Reply

Quote:
Originally Posted by Roberto80
Посмотреть сообщение
If u use \ in the last of a line starting with // ,u will get errors as shit,lol it took alone time to find this shitty erros xD
It is because \ is used to tell that compiler that the line hasn't ended yet.

Код:
#define TEST "ABCDEFG \
HIJKLMN \
OPQRSTUVWXYZ"
And the error which you get when you do that on a comment line is a bug!
Reply

Quote:
Originally Posted by Yashas
Посмотреть сообщение
It is because \ is used to tell that compiler that the line hasn't ended yet.

Код:
#define TEST "ABCDEFG \
HIJKLMN \
OPQRSTUVWXYZ"
And the error which you get when you do that on a comment line is a bug!
Actually I think I recall (Y-Less) someone saying that Pawn was supposed to have comment continuation, I recently tested it and it doesn't work.
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)