SA-MP Forums Archive
Why do we Use...... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Why do we Use...... (/showthread.php?tid=558599)



Why do we Use...... - TheRaGeLord - 18.01.2015

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



Re: Why do we Use...... - Lordzy - 18.01.2015

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.


Re: Why do we Use...... - Schneider - 18.01.2015

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


Re: Why do we Use...... - Sew_Sumi - 18.01.2015

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.


Re: Why do we Use...... - Vince - 18.01.2015

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


Re: Why do we Use...... - ATGOggy - 18.01.2015

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.