SA-MP Forums Archive
return -1; - 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: return -1; (/showthread.php?tid=322009)



return -1; - nuriel8833 - 29.02.2012

Just a tiny question:
In some codes I've seen that there is a return -1; (usually when something is invaild)
What does it do and what is its usages?
Thanks 4 helping


Re: return -1; - Vince - 29.02.2012

Returning a value is only relevant if that value is actually used in an assignment or a comparison. Most people tend to use -1 as an invalid value if a valid value that can be returned also includes 0 (e.g. an array index or playerid).

However, it is advised to use INVALID_PLAYER_ID, INVALID_VEHICLE_ID, etc if an invalid value is to be returned. This makes it easier to check and easier to read when viewing that part of the code again several weeks or months later.


Re: return -1; - nuriel8833 - 29.02.2012

Alright thanks a lot both