Array index of bounds?
#1

[19:56:02] [debug] Run time error 4: "Array index out of bounds"
[19:56:02] [debug] Accessing element at index 35 past array upper bound 34
[19:56:02] [debug] AMX backtrace:
[19:56:02] [debug] #0 0004889c in public OnPlayerEnterRaceCheckpoint (0) from krp.amx
[19:57:05] [CMDS] Nicusss: /exam


pawn Код:
public OnPlayerEnterRaceCheckpoint(playerid)
{
    if(TakingDMVLicense[playerid] != 0)
    {
        new id = dmvcheckpointid[playerid];
        if(id == 34)
        {
            DisablePlayerRaceCheckpoint(playerid);
            PlayerInfo[playerid][pCarLic] = 1;
            PlayerInfo[playerid][pCarLicExp] = 460;
            dmvcheckpointid[playerid] = 0;
            TakingDMVLicense[playerid] = 0;
            GameTextForPlayer(playerid, "~Y~done.", 5000, 3);
        }
        new string[456];
        format(string, sizeof(string), "dmv ~R~%d~W~ din ~R~%d",dmvcheckpointid[playerid] ,sizeof(DMVCheckPointsurile) -1);
        PlayerTextDrawSetString(playerid, JobHint[playerid], string);
        dmvcheckpointid[playerid] += 1;
        if(id == 33)
        {
            SetPlayerRaceCheckpoint(playerid,1,DMVCheckPointsurile[34][0],DMVCheckPointsurile[34][1],DMVCheckPointsurile[34][2],
            0,0,0,8);
        }
        else
        {
            SetPlayerRaceCheckpoint(playerid,0,DMVCheckPointsurile[id][0],DMVCheckPointsurile[id][1],DMVCheckPointsurile[id][2],
            DMVCheckPointsurile[id + 1][0],DMVCheckPointsurile[id + 1][1],DMVCheckPointsurile[id + 1][2],8);
        }

    }
    return 1;
}
stock:

pawn Код:
new Float:DMVCheckPointsurile[][] = {
    {2079.8010000,-1908.9489000,12.9888000,359.2701000},
    {2092.0793000,-1765.1726000,13.0224000,344.2515000},
    {2155.7454000,-1754.4882000,13.0139000,271.2896000},
    {2188.3357000,-1712.9950000,12.9669000,357.4161000},
    {2210.8508000,-1592.9163000,20.5355000,348.4839000},
    {2214.3303000,-1459.2034000,23.4506000,1.1416000},
    {2228.9482000,-1387.7413000,23.4558000,270.0196000},
    {2305.8645000,-1357.5271000,23.4801000,0.0323000},
    {2306.0806000,-1167.1633000,26.0930000,0.2280000},
    {2230.0383000,-1132.9138000,25.2496000,75.7665000},
    {2085.5313000,-1049.1210000,30.0760000,51.5912000},
    {1905.1628000,-1018.1371000,35.3524000,82.1078000},
    {1744.8513000,-954.8079000,46.9623000,89.5103000},
    {1599.1042000,-1060.7581000,54.1893000,162.4083000},
    {1610.6638000,-1234.9495000,49.1590000,173.8582000},
    {1579.9979000,-1402.2487000,28.0843000,151.4133000},
    {1605.4967000,-1525.1771000,19.2153000,242.0585000},
    {1716.2003000,-1532.8170000,20.1792000,287.1696000},
    {1888.9093000,-1519.6547000,2.8640000,267.3655000},
    {2031.3407000,-1555.9702000,7.0833000,193.1949000},
    {1999.2223000,-1626.1582000,13.0076000,175.0042000},
    {1986.9753000,-1749.7250000,13.0078000,93.6675000},
    {1835.4277000,-1750.3364000,13.0075000,90.4663000},
    {1762.9684000,-1730.1244000,13.0073000,87.2267000},
    {1580.4890000,-1729.6383000,13.0077000,89.6128000},
    {1566.8966000,-1857.9626000,13.0077000,179.2133000},
    {1542.6873000,-1869.7743000,13.0074000,92.8948000},
    {1528.4139000,-2023.7837000,28.5611000,184.7209000},
    {1638.9050000,-2162.4834000,22.4115000,254.8095000},
    {1805.9771000,-2168.8030000,13.0074000,269.8712000},
    {1945.8691000,-2169.1184000,13.0146000,269.8695000},
    {1964.2424000,-2086.6626000,13.0148000,0.1208000},
    {1964.0325000,-1964.7639000,13.2361000,0.0676000},
    {1989.4751000,-1935.4274000,13.0078000,268.7886000},
    {2080.0886,-1929.8861,13.1640,32.0}


};
Reply
#2

If you have entered last checkpoint, this code is executed:
Код:
dmvcheckpointid[playerid] += 1;
Now variable is 35!

And there is a code:
Код:
if(id == 33)
		{
			SetPlayerRaceCheckpoint(playerid,1,DMVCheckPointsurile[34][0],DMVCheckPointsurile[34][1],DMVCheckPointsurile[34][2],
			0,0,0,8);
		}
		else
		{
			SetPlayerRaceCheckpoint(playerid,0,DMVCheckPointsurile[id][0],DMVCheckPointsurile[id][1],DMVCheckPointsurile[id][2],
			DMVCheckPointsurile[id + 1][0],DMVCheckPointsurile[id + 1][1],DMVCheckPointsurile[id + 1][2],8);
		}
Exactly here:
Код:
else // It mean 34, 35, 36, 37... ETC!
		{
			SetPlayerRaceCheckpoint(playerid,0,DMVCheckPointsurile[id][0],DMVCheckPointsurile[id][1],DMVCheckPointsurile[id][2],
			DMVCheckPointsurile[id + 1][0],DMVCheckPointsurile[id + 1][1],DMVCheckPointsurile[id + 1][2],8);
Just change to:
Код:
else if(id < 33)
		{
			SetPlayerRaceCheckpoint(playerid,0,DMVCheckPointsurile[id][0],DMVCheckPointsurile[id][1],DMVCheckPointsurile[id][2],
			DMVCheckPointsurile[id + 1][0],DMVCheckPointsurile[id + 1][1],DMVCheckPointsurile[id + 1][2],8);
		}
Reply
#3

Thanks anyway.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)