How does INVALID_PLAYER_ID actually work? -
Puppy - 27.01.2015
Now, this may seem a bit silly but I am basically curious about how INVALID_PLAYER_ID works. Let's start with this example:
pawn Код:
public OnPlayerUpdate(playerid)
{
if(playerid != INVALID_PLAYER_ID)
{
.///
}
return 1;
}
This would allow the code to go through if the player is connected. But my question is what exactly is INVALID_PLAYER_ID? A function? If it's a constant value then this would make zero sense.
This is what the compiler sees this as:
if(0 !=
So, playerID obviously can be anything, but what about INVALID_PLAYER_ID? If it's a constant then it certainly can't be 0,1,2,3,4,5,6... How does this work?
Is it basically just a marco for a native function like IsPlayerConnected?
Thanks.
EDIT: In a_samp it's defined as
pawn Код:
#define INVALID_PLAYER_ID (0xFFFF)
This makes zero sense, is this like a memory address? Or is it basically something to do with bits?
Re: How does INVALID_PLAYER_ID actually work? -
DRIFT_HUNTER - 27.01.2015
Its a simple define, from code you can see its defined as hexadecimal number
0xFFFF - FFFF is 65535 in decimal whitch is maximum signed integer for 32bit
65535 as player id is invalid for sure and thats why its used as invalid player id
Re: How does INVALID_PLAYER_ID actually work? -
Puppy - 27.01.2015
That doesn't answer my question. Let's say no one is using playerID 0. And when I run a global timer(which I wouldn't but you get the point) to check if player 0 is online every 5 minutes...
pawn Код:
if(0 == 65535)
{
// player is offline
}
This doesn't make any sense. This is not equal(0 doesn't equal 65535 that'd be crazy!), so how does the compiler actually process this information?
Re: How does INVALID_PLAYER_ID actually work? -
Vince - 27.01.2015
Quote:
Originally Posted by DRIFT_HUNTER
65535 in decimal whitch is maximum signed integer for 32bit
|
16 bit. Also some callbacks use this value, namely OnPlayerDeath.
Quote:
Originally Posted by Puppy
That doesn't answer my question. Let's say no one is using playerID 0. And when I run a global timer(which I wouldn't but you get the point) to check if player 0 is online every 5 minutes...
pawn Код:
if(0 == 65535) { // player is offline }
This doesn't make any sense. This is not equal(0 doesn't equal 65535 that'd be crazy!), so how does the compiler actually process this information?
|
Don't confuse it with IsPlayerConnected, because for the most part they can't be used interchangeably.
Re: How does INVALID_PLAYER_ID actually work? -
Ada32 - 27.01.2015
Quote:
Originally Posted by Puppy
This makes zero sense, is this like a memory address?
|
nope
Quote:
Originally Posted by Puppy
Or is it basically something to do with bits?
|
yup
Quote:
Originally Posted by DRIFT_HUNTER
0xFFFF - FFFF is 65535 in decimal whitch is maximum signed integer for 32bit
|
16*
Quote:
Originally Posted by DRIFT_HUNTER
65535 as player id is invalid for sure and thats why its used as invalid player id
|
so is -1..
just the max val of 2 byte int (samp got 1000p on the linux server..cool)
Re: How does INVALID_PLAYER_ID actually work? -
DRIFT_HUNTER - 27.01.2015
Quote:
Originally Posted by Vince
16 bit. Also some callbacks use this value, namely OnPlayerDeath.
Don't confuse it with IsPlayerConnected, because for the most part they can't be used interchangeably.
|
16bit unsigned, 32bit signed :P
Re: How does INVALID_PLAYER_ID actually work? -
Ada32 - 27.01.2015
Quote:
Originally Posted by DRIFT_HUNTER
16bit unsigned, 32bit signed :P
|
uh..no
Re: How does INVALID_PLAYER_ID actually work? -
DRIFT_HUNTER - 27.01.2015
Quote:
Originally Posted by Ada32
uh..no
|
Oooopsss.... my bad

Anyway 65535 is maximum unsigned in 16 bits, and C/C++ integer is 2 bytes (2*8 = 16bits)
Re: How does INVALID_PLAYER_ID actually work? -
ikkentim - 27.01.2015
Used to indicate that no player matches the description
E.g. The killerid on suicide.
https://sampwiki.blast.hk/wiki/OnPlayerDeath
Re: How does INVALID_PLAYER_ID actually work? -
Puppy - 28.01.2015
I know what it does, it's just I am stumped upon the fact of how it works anyways thanks for the help so far, can someone explain this in layman(simple) terms?