Posts: 1,157
Threads: 176
Joined: Jun 2009
Reputation:
0
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
Posts: 10,066
Threads: 38
Joined: Sep 2007
Reputation:
0
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.