PDA

View Full Version : array index out of bounds


Pearson
14/12/2016, 01:01 AM
Hello. I need another help :P.
Heres my code.

new lootCount;
enum hospinfo
{
HospitalID,
Float:xHos,
Float:yHos,
Float:zHos,
HosSlot1 = 1,
HosSlot2 = 1,
HosSlot3 = 1,
HosSlot4 = 1,
HosSlot5 = 1,
HosSlot6 = 1
}
new Medikament[MAX_LOOTING][hospinfo];


if(newkeys == 1024)
{
if(IsPlayerInRangeOfPoint(playerid,3.5,Medikament[GetMedikID(playerid)][xHos],Medikament[GetMedikID(playerid)][yHos],Medikament[GetMedikID(playerid)][zHos]))
{
HospitalBoxDispl(playerid);
}
}

ERROR:

D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(8330) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26392) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26446) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26447) : error 032: array index out of bounds (variable "Medikament")

Thanks for help

Hansrutger
14/12/2016, 01:32 AM
How does your GetMedikID(playerid) look like?

Pearson
14/12/2016, 01:34 AM
Here is it

stock GetMedikID(playerid)
{
for(new i=0; i<MAX_LOOTING; i++)
{
if(IsPlayerInRangeOfPoint(playerid,3.5, Medikament[i][xHos],Medikament[i][yHos],Medikament[i][zHos]))
{
return i;
}
}
return 0;
}

Unrea1
14/12/2016, 01:38 AM
Replace:

stock GetMedikID(playerid)
{
for(new i = 0; i < sizeof(Medikament); i++)
{
if(IsPlayerInRangeOfPoint(playerid,3.5, Medikament[i][xHos],Medikament[i][yHos],Medikament[i][zHos]))
{
return i;
}
}
return 0;
}

if(newkeys == 1024)
{
if(HospitalBoxDispl(playerid) != 0) return HospitalBoxDispl(playerid);
}

Pearson
14/12/2016, 01:45 AM
I have error again.

stock GetMedikID(playerid)
{
for(new i = 0; i < sizeof(Medikament); i++)
{
if(IsPlayerInRangeOfPoint(playerid,3.5, Medikament[i][xHos],Medikament[i][yHos],Medikament[i][zHos])) // ERROR 1
{
return i;
}
}
return 0;
}


forward HospitalCreate(Float:pXX,Float:pYX,Float:pZX);
public HospitalCreate(Float:pXX,Float:pYX,Float:pZX)
{
new hospstrng[128];
lootCount += 1;
Medikament[lootCount][HosSlot1] = 1;
Medikament[lootCount][HosSlot2] = 1;
Medikament[lootCount][HosSlot3] = 1;
Medikament[lootCount][HosSlot4] = 1;
Medikament[lootCount][HosSlot5] = 1;
Medikament[lootCount][HosSlot6] = 1;
Medikament[lootCount][xHos] = pXX;
Medikament[lootCount][yHos] = pYX;//ERROR 2
Medikament[lootCount][zHos] = pZX;// ERROR 3
Medikament[lootCount][HospitalID] = CreateDynamicObject(1685,pXX+0.3,pYX+float(1),pZX-0.7,0.0,0.0,0.0,-1,-1,-1,1000.0);
format(hospstrng,sizeof(hospstrng),"{05FB0C}MEDBOX\n{8C8F90}Daachiret Marcxena ALT-s Rom Naxo Medikamentebis Yutis Inventari");
CreateDynamic3DTextLabel(hospstrng,-1,pXX+0.3,pYX+float(1),pZX-0.7,8.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,1,-1,-1,-1, 8.0);
return 1;
}

ERRORS

D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26389) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26443) : error 032: array index out of bounds (variable "Medikament")
D:\1-ADMIN-ar cashaloo\Desktop\DayZ\gamemodes\dayz1.pwn(26444) : error 032: array index out of bounds (variable "Medikament")
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase

Hansrutger
14/12/2016, 02:04 AM
Right I forgot this already about enums lel.

http://forum.sa-mp.com/showthread.php?t=318307

I'm not sure if it's going to solve your problem but basically setting this:

HosSlot1 = 1,
HosSlot2 = 1,
HosSlot3 = 1,
HosSlot4 = 1,
HosSlot5 = 1,
HosSlot6 = 1

Means that you are assigning them all to the first position (well second). Like I said, this might not actually solve the array out of bound but it's just generally a bad idea to assign values to enum variables because you're not actually assigning values. Enum's are constants and act as "holders" for numbers.

Pearson
14/12/2016, 02:08 AM
Right I forgot this already about enums lel.

http://forum.sa-mp.com/showthread.php?t=318307

I'm not sure if it's going to solve your problem but basically setting this:

HosSlot1 = 1,
HosSlot2 = 1,
HosSlot3 = 1,
HosSlot4 = 1,
HosSlot5 = 1,
HosSlot6 = 1

Means that you are assigning them all to the first position (well second). Like I said, this might not actually solve the array out of bound but it's just generally a bad idea to assign values to enum variables because you're not actually assigning values. Enum's are constants and act as "holders" for numbers.

Fixed Thanks for help . +REP