PDA

View Full Version : can't fix error 032: array index out of bounds


aqu
19/01/2012, 07:44 PM
enum wnt
{
WeaponNames[ 256 ]
}
new weaponnames[MAX_TEAMS][wnt]= {
{ "- Primary~n- Deagle(100)~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"}
};

// Somewhere in the script
playerclass[playerid]=1;
new string[256];
format(string,sizeof(string),"%s",weaponnames[playerclass[playerid]][wnt]);
TextDrawSetString(OPRQwnp[playerid],string);
TextDrawShowForPlayer(playerid,OPRQwnp[playerid]);


C:\Users\Tadas\Desktop\Gang Wars\gamemodes\SSSGW.pwn(809) : error 032: array index out of bounds (variable "weaponnames")

help ;(

Vince
19/01/2012, 08:06 PM
How is MAX_TEAMS defined?

aqu
19/01/2012, 08:12 PM
defined as 10

MP2
19/01/2012, 08:28 PM
It's tertiary, not thirdly.

Also, the array doesn't make sense. What exactly are you trying to do?

aqu
19/01/2012, 08:31 PM
EDIT: deleted

aqu
19/01/2012, 08:35 PM
I am going to make,that it will show weapons on player request class,that player will have if he spawn as that class.
Here's code:

// On the top
new playerclass[MAX_PLAYERS];
new Text:OPRQwnp[MAX_PLAYERS];

enum wnt
{
WeaponNames[ 256 ]
}
new weaponnames[MAX_TEAMS][wnt]= {
{ "- Primary~n- Deagle(100)~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"},
{ "- Primary~n- Secondary~n- Thirdly"}
};

// On Player connects
OPRQwnp[playerid] = TextDrawCreate(9.000000, 150.000000, "- Primary(100)");
TextDrawBackgroundColor(OPRQwnp[playerid], 255);
TextDrawFont(OPRQwnp[playerid], 1);
TextDrawLetterSize(OPRQwnp[playerid], 0.500000, 1.000000);
TextDrawColor(OPRQwnp[playerid], -1);
TextDrawSetOutline(OPRQwnp[playerid], 0);
TextDrawSetProportional(OPRQwnp[playerid], 1);
TextDrawSetShadow(OPRQwnp[playerid], 1);

// On player request class
public OnPlayerRequestClass(playerid, classid)
{
SetPlayerClass( playerid, classid );
SetPlayerColor( playerid, COLOR_INACTIVE );
PlayerPlaySound( playerid, 1068, 0.0, 0.0, 0.0 );

switch(classid)
{
case 0:
{
playerclass[playerid]=1;
SetPlayerPos(playerid,2772.5334,-2382.5310,18.9217);
SetPlayerCameraPos(playerid,2776.8987,-2377.0911,18.9217);
SetPlayerCameraLookAt(playerid,2772.5334,-2382.5310,18.9217);
SetPlayerFacingAngle(playerid,294.2843);
ApplyAnimation(playerid,"LOWRIDER", "RAP_B_Loop",4.0,1,1,1,1,1);
}
}
new string[256];
format(string,sizeof(string),"%s",weaponnames[playerclass[playerid]][wnt]);
TextDrawSetString(OPRQwnp[playerid],string);
TextDrawShowForPlayer(playerid,OPRQwnp[playerid]);
return 1;
}

Tannz0rz
19/01/2012, 08:43 PM
It'd be easier on everyone's behalf if you specified which line is line 809. The only thing that comes to mind is that playerclass[playerid] is either less than 0 or greater than 9.

EDIT: After further review I've come to notice this:
weaponnames[playerclass[playerid]][wnt]

Change it to:
weaponnames[playerclass[playerid]][WeaponNames]

Also, I suggest you remove "string" from the combination entirely. Just use
TextDrawSetString(OPRQwnp[playerid], weaponnames[playerclass[playerid]][WeaponNames]);

aqu
19/01/2012, 08:47 PM
oh,yeah,stupid mistake.Thank you all. +rep for all.