SA-MP Forums Archive
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: Array index out of bounds. (/showthread.php?tid=497860)



Array index out of bounds. - rangerxxll - 28.02.2014

So I'm trying to make random spawns which i did perfect a few days ago, but for some reason I'm beginning to get errors. Can someone spot the problem?

pawn Код:
new Float:rSpawns[0][3] =
{
    {3878.7217,466.0317,7.4426},
    {3726.5127,263.8537,7.4798},
    {3695.7917,421.2384,7.4630},
    {3640.9050,344.2969,7.4534},
    {3967.2261,423.8549,28.4928},
    {3928.4590,301.3971,38.8480}
};


new rand = random(sizeof(rSpawns));
    SetPlayerPos(playerid, rSpawns[rand][0], rSpawns[rand][1], rSpawns[rand][2], rSpawns[rand][3], rSpawns[rand][4], rSpawns[rand][5]);
Thank you for any assistance.


Re: Array index out of bounds. - Jefff - 28.02.2014

Should be
pawn Код:
new Float:rSpawns[6][3] = // 6 lines and 3 positions X,Y,Z
or
pawn Код:
new Float:rSpawns[][] =
and SetPlayerPos have 4 aguments not 7


Re: Array index out of bounds. - Golimad - 28.02.2014

pawn Код:
new Float:rSpawns[6][3] =
{
    {3878.7217,466.0317,7.4426},
    {3726.5127,263.8537,7.4798},
    {3695.7917,421.2384,7.4630},
    {3640.9050,344.2969,7.4534},
    {3967.2261,423.8549,28.4928},
    {3928.4590,301.3971,38.8480}
};


new rand = random(sizeof(rSpawns));
    SetPlayerPos(playerid, rSpawns[rand][0], rSpawns[rand][1], rSpawns[rand][2]);
There you go


Re: Array index out of bounds. - rangerxxll - 28.02.2014

Thank you. Quick question for future reference.

When you're adding the zero in
pawn Код:
rSpawns[rand][0]
would that be the X axis? And the 1 and 2 would be considered Y and Z? Because i was thinking it meant the coordinate number in the array.


Re: Array index out of bounds. - MP2 - 01.03.2014

Yes. Index 0 is the first value in the array, which in this case is the X coordinate.


Re: Array index out of bounds. - rangerxxll - 01.03.2014

Ah, no wonder why I was doing it wrong. Thank you.