Array out of index. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Array out of index. (
/showthread.php?tid=651021)
Array out of index. -
ivndosos - 11.03.2018
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;
}
Re: Array out of index. -
Lokii - 11.03.2018
PHP код:
new gRandomSpawns[gRandom][more than 3]; //same with enum
Re: Array out of index. -
ivndosos - 12.03.2018
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.