SA-MP Forums Archive
Run time error 4: "Array index out of bounds" - 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: Run time error 4: "Array index out of bounds" (/showthread.php?tid=568506)



Run time error 4: "Array index out of bounds" - benel1 - 22.03.2015

pawn Код:
[20:54:20] [debug] Run time error 4: "Array index out of bounds"
[20:54:20] [debug]  Accessing element at negative index -1
[20:54:20] [debug] AMX backtrace:
[20:54:20] [debug] #0 000781c0 in public OnPlayerEnterDynamicCP (3, 5) from PerfectDM.amx
My code:
pawn Код:
if(checkpointid == Player[playerid][MissionBankTimerAndCP])
    {
        if(Player[playerid][PlayerBankRob] > 0)
        {
            DestroyDynamicCP(Player[playerid][MissionBankTimerAndCP]);
            DestroyDynamic3DTextLabel(Player[playerid][MissionBank3DText]);
            TogglePlayerDynamicCP(playerid, Server[MissionBankCP], 1);
            UpdateBank(playerid, Player[playerid][PlayerBankRob]);
            Message(-1, Red, "[Bank] >> "white"!הצליח לשדוד את הבנק \"%s\" השחקן", GetName(Player[playerid][MissionBankTargetID]), GetName(playerid));
            Message(-1, Red, "[Bank] >> "green"$%s "white":סכום השוד", GetNum(Player[playerid][PlayerBankRob]));
            GivePlayerMoney(playerid, -Player[playerid][PlayerBankRob]);
            return Player[playerid][PlayerBankRob] = 0, 1;
        }
        return 1;
    }
I see no problem with the code ... :/


AW: Run time error 4: "Array index out of bounds" - Sascha - 22.03.2015

maybe forgot some of these index fields in the enum?


Re: AW: Run time error 4: "Array index out of bounds" - benel1 - 22.03.2015

Quote:
Originally Posted by Sascha
Посмотреть сообщение
maybe forgot some of these index fields in the enum?
I did not understand what you mean...
enum:
pawn Код:
...
        MissionBankTimerAndCP,
        PlayerBankRob,
    Text3D:MissionBank3DText,
    MissionBankTargetID,
        ...



Re: Run time error 4: "Array index out of bounds" - Konstantinos - 22.03.2015

Compile with -d3: https://github.com/Zeex/samp-plugin-...ith-debug-info

In case you don't have the latest version of crashdetect plugin, it's recommended to update it and try to reproduce the crash. After that, you'll get more information to the logs such as the line.


AW: Run time error 4: "Array index out of bounds" - Sascha - 22.03.2015

I've been using your code, the failure seems to be in the "Message" Function
what's the code of it?


Re: Run time error 4: "Array index out of bounds" - benel1 - 22.03.2015

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Compile with -d3: https://github.com/Zeex/samp-plugin-...ith-debug-info

In case you don't have the latest version of crashdetect plugin, it's recommended to update it and try to reproduce the crash. After that, you'll get more information to the logs such as the line.
I compile with -d3 and it not show me anything... :\

i downloaded the lastat version of crashdetect and still got this:
pawn Код:
[22:05:06] [debug] Run time error 4: "Array index out of bounds"
[22:05:06] [debug]  Accessing element at negative index -1
[22:05:06] [debug] AMX backtrace:
[22:05:06] [debug] #0 00078588 in public OnPlayerEnterDynamicCP (3, 5) from PerfectDM.amx
Quote:
Originally Posted by Sascha
Посмотреть сообщение
I've been using your code, the failure seems to be in the "Message" Function
what's the code of it?
pawn Код:
stock Message(playerid, color, const message[], va_args<>)
{
    if(playerid == -1 || playerid == INVALID_PLAYER_ID)
    {
        #pragma unused playerid
        return SendClientMessageToAll(color, va_return(message, va_start<3>));
    }
    else return SendClientMessage(playerid, color, va_return(message, va_start<3>));
}
I use it alot in the gamemode and this is the first time i got this error
---
Sorry for my bad english :P


Re: Run time error 4: "Array index out of bounds" - Konstantinos - 22.03.2015

Did it show more information at the compiler output? And if so, did you run the new file (the .amx one) you got after compiling? If done the above and it still does not show the line, then you'll have to do it with the old way. print messages before and after a certain line and see what's the last part was executed.


Re: Run time error 4: "Array index out of bounds" - benel1 - 22.03.2015

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Did it show more information at the compiler output? And if so, did you run the new file (the .amx one) you got after compiling? If done the above and it still does not show the line, then you'll have to do it with the old way. print messages before and after a certain line and see what's the last part was executed.
No it didn't show me more information
i tried the print but it's not help just print
pawn Код:
[19:27:48] Error
[19:27:48] Error
[19:27:48] Error
[19:27:48] Error
[19:27:48] Error
[19:27:48] [debug] Run time error 4: "Array index out of bounds"
[19:27:48] [debug]  Accessing element at negative index -1
[19:27:48] [debug] AMX backtrace:
[19:27:48] [debug] #0 00078318 in public OnPlayerEnterDynamicCP (3, 5) from PerfectDM.amx



Re: Run time error 4: "Array index out of bounds" - Konstantinos - 22.03.2015

That's why it didn't show up anything. Some users in the past didn't have the file with extension .cfg and that was the problem so you may need to check it again.

With the old way of debugging I meant:
PHP код:
if(checkpointid == Player[playerid][MissionBankTimerAndCP])
{
    if(
Player[playerid][PlayerBankRob] > 0)
    {
        
DestroyDynamicCP(Player[playerid][MissionBankTimerAndCP]);
        print(
"OPEDCP: Destroyed CP");
        
DestroyDynamic3DTextLabel(Player[playerid][MissionBank3DText]);
        print(
"OPEDCP: Destroyed 3D Label");
        
TogglePlayerDynamicCP(playeridServer[MissionBankCP], 1);
        print(
"OPEDCP: Toggled CP");
        
UpdateBank(playeridPlayer[playerid][PlayerBankRob]);
        print(
"OPEDCP: Updated Bank");
        
Message(-1Red"[Bank] >> "white"!הצליח לשדוד את הבנק \"%s\" השחקן"GetName(Player[playerid][MissionBankTargetID]), GetName(playerid));
        print(
"OPEDCP: Message Sent (1)");
        
Message(-1Red"[Bank] >> "green"$%s "white":סכום השוד"GetNum(Player[playerid][PlayerBankRob]));
        print(
"OPEDCP: Message Sent (2)");
        
GivePlayerMoney(playerid, -Player[playerid][PlayerBankRob]);
        print(
"OPEDCP: Gave Money");
        
Player[playerid][PlayerBankRob] = 0;
        print(
"OPEDCP: Reset Variable");
    }




Respuesta: Run time error 4: "Array index out of bounds" - alexus - 22.03.2015

What does it mean: return Player[playerid][PlayerBankRob] = 0, 1;

Perhaps you would say: return Player[playerid][PlayerBankRob] = 0;