Array out of index.
#1

What causes this error?

Код:
SetPlayerFacingAngle(playerid,gRandomSpawns[gRandom][3]);
Код:
error 032: array index out of bounds (variable "gRandomSpawns")
Код:
public OnPlayerSpawn(playerid)
{
   new
		str[128],
		PlayerName[MAX_PLAYER_NAME];

   GetPlayerName(playerid, PlayerName, sizeof(PlayerName));

   format(str, sizeof(str), "%s has successfully spawned!", PlayerName);

   SendClientMessageToAll(-1, str);
   
   new gRandom = random(sizeof(gRandomSpawns));
   
   SetPlayerPos(playerid,
   gRandomSpawns[gRandom][0],
   gRandomSpawns[gRandom][1],
   gRandomSpawns[gRandom][2]);
   
   SetPlayerFacingAngle(playerid,gRandomSpawns[gRandom][3]);
   
   return true;
}
Reply
#2

PHP код:
new gRandomSpawns[gRandom][more than 3]; //same with enum 
Reply
#3

For some reason it spawns me not even in the right coordinates, my coordinates are correct but I don't know what's the problem, my code seems to be alright as well.

In the tutorial it even said to put [3] but when I do that I get array out of bounds, the max number is only 2.





Edit: fixed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)