Posts: 314
Threads: 103
Joined: Jun 2014
Hello guys, Today I Wanna Know That Why Do We Use -1 In Codes Eg.
pawn Код:
1st Eg.
Died[playerid] = -1;
KilledBy[playerid] = -1;
2nd Eg.
SendClientMessagetoAll(-1.........
Posts: 2,698
Threads: 37
Joined: Mar 2012
Reputation:
0
It depends on how exactly the author of that snippet wanted it to be like. I use -1 to set default values for timer IDs since they start from ID 0. So, I can check if a timer exists or not by equating it to -1.
Posts: 515
Threads: 5
Joined: Jun 2007
Reputation:
0
...and in the case of the ClientMessages, putting -1 as the color, will result in a white text.
Posts: 6,242
Threads: 8
Joined: Jun 2008
Quote:
Originally Posted by TheRaGeLord
Hello guys, Today I Wanna Know That Why Do We Use -1 In Codes Eg.
pawn Код:
1st Eg. Died[playerid] = -1; KilledBy[playerid] = -1;
2nd Eg. SendClientMessagetoAll(-1.........
|
In the first instance it's a positive negative result... So it's guaranteed to not conflict with anything.
In the second, it means White when used with that function.
But really, there's no way unless assigned that -1 will turn up in a variable, without it intentionally being set.. Hence why people use it for the INVALID_DEFINE_HERE.
Posts: 10,066
Threads: 38
Joined: Sep 2007
Reputation:
0
-1 is usually used to indicate something is invalid, although there are usually better options available like INVALID_PLAYER_ID, INVALID_VEHICLE_ID, etc.
In the second example it's just a quick way to write "white"; -1 is equal to 0xFFFFFFFF which is pure white.
Posts: 850
Threads: 29
Joined: Sep 2014
Reputation:
0
also if we are using a variable like 'lastkilledby[playerid]', we must set it to -1 because there can be players who have id 0.