Array index out of bounds.
#1

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.
Reply
#2

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
Reply
#3

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
Reply
#4

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.
Reply
#5

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)