Why do we Use......
#1

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

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

...and in the case of the ClientMessages, putting -1 as the color, will result in a white text.
Reply
#4

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)