SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 30/08/2019, 07:14 PM   #1
MaestrulFritz
Little Clucker
 
Join Date: Mar 2014
Location: Romania
Posts: 32
Reputation: 0
Default [debug] Run time error 4: "Array index out of bounds" problem

Hello everyone! I have this problem as I am very new to scripting

Code:
[debug] AMX backtrace:
[22:09:55] [debug] #0 004ae518 in public cmd_exitgarage (0, 10500072) from GM.amx
[22:09:55] [debug] #1 native CallLocalFunction () from samp-server.exe
[22:09:55] [debug] #2 0000089c in public OnPlayerCommandText (0, 10500024) from GM.amx
[22:09:57] [debug] Run time error 4: "Array index out of bounds"
[22:09:57] [debug]  Attempted to read/write array element at negative index -1
This is the command:

Code:
CMD:exitgarage(playerid, params[])
{
    if(pInfo[playerid][aVar][61] != -1 && IsPlayerInRangeOfPoint(playerid, 3.0, 1341.2281,-1548.8905,10037.3174))
    if(GetPlayerState(playerid) == 2)
    {
        SetVehicleVirtualWorld(pInfo[playerid][aVar][1], 0), SetVehiclePos(pInfo[playerid][aVar][1], Houses[pInfo[playerid][aVar][61]][GEnterX], Houses[pInfo[playerid][aVar][61]][GEnterY], Houses[pInfo[playerid][aVar][61]][GEnterZ]), SetPlayerPos(playerid, Houses[pInfo[playerid][aVar][61]][GEnterX], Houses[pInfo[playerid][aVar][61]][GEnterY], Houses[pInfo[playerid][aVar][61]][GEnterZ]),
        SetPlayerVirtualWorldEx(playerid, Iter_Contains(Warp, playerid) || Iter_Contains(Warp2, playerid) ? (pInfo[playerid][aVar][87]) : (0)), PutPlayerInVehicle(playerid, pInfo[playerid][aVar][1], 0);
        pInfo[playerid][aVar][61] = -1;
    }    
    if(GetPlayerState(playerid) == 1)
    {
        SetPlayerPos(playerid, Houses[pInfo[playerid][aVar][61]][GEnterX], Houses[pInfo[playerid][aVar][61]][GEnterY], Houses[pInfo[playerid][aVar][61]][GEnterZ]),
        SetPlayerVirtualWorldEx(playerid, Iter_Contains(Warp, playerid) || Iter_Contains(Warp2, playerid) ? (pInfo[playerid][aVar][87]) : (0)), 
        pInfo[playerid][aVar][61] = -1;
    }
    return 1;
}
I also got this :

Code:
[22:53:15] [debug] Run time error 4: "Array index out of bounds"
[22:53:15] [debug]  Attempted to read/write array element at negative index -1
[22:53:15] [debug] AMX backtrace:
[22:53:15] [debug] #0 003568c0 in public OnPlayerLogin (1) from GM.amx

Last edited by MaestrulFritz; 30/08/2019 at 07:58 PM.
MaestrulFritz is offline   Reply With Quote
Old 31/08/2019, 11:14 AM   #2
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,852
Reputation: 675
Default Re: [debug] Run time error 4: "Array index out of bounds" problem

your third if statment isn't under your first if statment, so aVar[61] can be -1 in your third if statement, either use brackets or only put one statment under a bracketless if statement

pawn Code:
// your structure
    if(/*code*/) // if#1
    if(/*code*/) // if#2, only valid after if#1
    if(/*code*/) // if#3, works without if#1
// either use this
    if(/*code*/) // if#1
    if(/*code*/) // if#2
    else if(/*code*/) // if#3
// or this
    if(/*code*/) // if#1
    {
        if(/*code*/) // if#2
        if(/*code*/) // if#3
    }
// or this
    if(/*code*/) // if#1
        switch(/*code*/)
        {
            case /*constant*/: // if#2
            case /*constant*/: // if#3
        }
// or this
    if(/*code*/) // if#1
    {
        switch(/*code*/)
        {
            case /*constant*/: // if#2
            case /*constant*/: // if#3
        }
    }
Also what is with these numbers from aVar, why not use an second enum?
Nero_3D is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[12:02:57] [debug] Run time error 4: "Array index out of bounds" [12:02:57] [debug] Attempted to read/write array eleme sonn51280 Scripting Help 5 13/07/2019 01:08 PM
[debug] Run time error 4: "Array index out of bounds" nGen.SoNNy Scripting Help 3 06/03/2019 04:16 PM
[debug] Run time error 4: "Array index out of bounds" cs_waller Scripting Help 2 13/11/2016 05:33 PM
[debug] Run time error 4: "Array index out of bounds" and many more errors :P ntmp Scripting Help 2 11/08/2014 02:10 PM
[debug] Run time error 4: "Array index out of bounds" gotwarzone Scripting Help 3 24/11/2013 03:59 PM


All times are GMT. The time now is 11:04 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.