SA-MP Forums Archive
return -1? it s ok to use it? or its better return 1/0? - 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? it s ok to use it? or its better return 1/0? (/showthread.php?tid=657150)



return -1? it s ok to use it? or its better return 1/0? - R3SpaWn0 - 01.08.2018

Hi, i found this in a gamemode and i think its causing my crashdetect say array -1 error..

PHP код:
Car_Nearest(playerid)
{
    static
        
Float:fX,
        
Float:fY,
        
Float:fZ;
    for (new 
0!= MAX_DYNAMIC_CARS++) if (CarData[i][carExists]) {
        
GetVehiclePos(CarData[i][carVehicle], fXfYfZ);
        if (
IsPlayerInRangeOfPoint(playerid3.0fXfYfZ)) {
            return 
i;
        }
    }
    return -
1;

PHP код:
Car_Inside(playerid)
{
    new 
carid;
    if (
IsPlayerInAnyVehicle(playerid) && (carid Car_GetID(GetPlayerVehicleID(playerid))) != -1)
        return 
carid;
    return -
1;

PHP код:
Business_NearestDeliver(playerid)
{
    for (new 
0!= MAX_BUSINESSES++) if (BusinessData[i][bizExists] && IsPlayerInRangeOfPoint(playerid5.0BusinessData[i][bizDeliver][0], BusinessData[i][bizDeliver][1], BusinessData[i][bizDeliver][2])) {
        return 
i;
    }
    return -
1;

why is using return -1? i dont understand, why not return 1??


Re: return -1? it s ok to use it? or its better return 1/0? - GRiMMREAPER - 01.08.2018

return -1 returns "true" (1), so I don't think the problem is related to the returned value. What is crashdetect outputting?


Re: return -1? it s ok to use it? or its better return 1/0? - R3SpaWn0 - 01.08.2018

Quote:
Originally Posted by GRiMMREAPER
Посмотреть сообщение
return -1 returns "true" (1), so I don't think the problem is related to the returned value. What is crashdetect outputting?
Код:
[debug] #0 000b8da8 in public OnPlayerExitVehicle (0x00000000, 0x0000000f) from roleplay.amx
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at negative index -1
[debug] AMX backtrace:
[debug] #0 000b8da8 in public OnPlayerExitVehicle (0x00000001, 0x0000000f) from roleplay.amx
[debug] Run time error 4: "Array index out of bounds"
[debug]  Accessing element at negative index -1
[debug] AMX backtrace:
[debug] #0 000b8da8 in public OnPlayerExitVehicle (0x00000001, 0x0000000f) from roleplay.amx
Is turning me this.. i posted the script here,

https://sampforum.blast.hk/showthread.php?tid=657147


Can you know?


Re: return -1? it s ok to use it? or its better return 1/0? - Akeem - 02.08.2018

Can you post your OnPlayerExitVehicle section?


Re: return -1? it s ok to use it? or its better return 1/0? - coool - 02.08.2018

for vehicles you should return the already defined "INVALID_VEHICLE_ID" instead of -1