Your array spawnpoints has either less than 5 entries or one of the arrays (spawnpoints[0]
, spawnpoints[1]
, spawnpoints[2]
, spawnpoints[3]
, spawnpoints[4]
) has less than 3 entries. Try debugging your code.
Array index out of bounds error Pawn
سؤال
I am using spawn points but when it compiles I'm getting this error:
Array index out of bounds
On this line is the error
for(new i =0 ; i < 5 ;i++) {
SetPlayerPos(playerid, spawnpoints[i][0], spawnpoints[i][1], spawnpoints[i][2]);
}
Hoping somebody knows the solution to the error.
المحلول
نصائح أخرى
Replace 5 with sizeof(spawnpoints)
. If you still get the error after this, then your spawnpoints array doesn't contain an x, y and z coordinate (and so is incorrectly structured.)
SetPlayerPos(playerid, Float:x, Float:y, Float:z);
Are spawnpoints defined with Float?
new Float:OldPos[MAX_PLAYERS][3];
Try with this example:
new Float:OldPos[MAX_PLAYERS][3];
GetPlayerPos(i, OldPos[i][0], OldPos[i][1], OldPos[i][2]);
لا تنتمي إلى StackOverflow