return -1;
#1

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

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

Alright thanks a lot both
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)