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

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

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

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?
Reply
#4

Can you post your OnPlayerExitVehicle section?
Reply
#5

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


Forum Jump:


Users browsing this thread: 1 Guest(s)