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
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
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.