简体   繁体   中英

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.

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.

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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM