SA-MP Forums Archive
array index out of bounds - 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 index out of bounds (/showthread.php?tid=524950)



array index out of bounds - Facerafter - 09.07.2014

Code:
 error 032: array index out of bounds (variable "DevBug")
 error 032: array index out of bounds (variable "DevBug")
 error 032: array index out of bounds (variable "DevBug")
pawn Code:
stock LoadBugs()
{
    new file[64];
    format(file, sizeof(file), "buglist.ini");
    format(DevBug[1][dBugs], 128, "%s", dini_Get(file, "BR1"));
    format(DevBug[2][dBugs], 128, "%s", dini_Get(file, "BR2"));
    format(DevBug[3][dBugs], 128, "%s", dini_Get(file, "BR3"));
    format(DevBug[4][dBugs], 128, "%s", dini_Get(file, "BR4"));
    format(DevBug[5][dBugs], 128, "%s", dini_Get(file, "BR5"));
    format(DevBug[6][dBugs], 128, "%s", dini_Get(file, "BR6"));
    format(DevBug[7][dBugs], 128, "%s", dini_Get(file, "BR7"));
    format(DevBug[8][dBugs], 128, "%s", dini_Get(file, "BR8"));
    format(DevBug[9][dBugs], 128, "%s", dini_Get(file, "BR9"));
    format(DevBug[10][dBugs], 128, "%s", dini_Get(file, "BR10"));
    format(DevBug[11][dBugs], 128, "%s", dini_Get(file, "BR11"));
    format(DevBug[12][dBugs], 128, "%s", dini_Get(file, "BR12"));
    format(DevBug[13][dBugs], 128, "%s", dini_Get(file, "BR13"));
    format(DevBug[14][dBugs], 128, "%s", dini_Get(file, "BR14"));
    format(DevBug[15][dBugs], 128, "%s", dini_Get(file, "BR15"));
    return 1;
}
pawn Code:
new DevBug[MAX_BUGS][dBugs];
#define MAX_BUGS 16



Re: array index out of bounds - Sawalha - 09.07.2014

Try to define MAX_BUGS then define DevBug and counting in scripting is from zero , so it will be like this if 16 :
pawn Code:
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15



Re: array index out of bounds - DavidSparks - 09.07.2014

You can also try this.
pawn Code:
stock LoadBugs() { new file[64]; format(file, sizeof(file), "buglist.ini"); format(DevBug[0][dBugs], 128, "%s", dini_Get(file, "BR1")); format(DevBug[1][dBugs], 128, "%s", dini_Get(file, "BR2")); format(DevBug[2][dBugs], 128, "%s", dini_Get(file, "BR3")); format(DevBug[3][dBugs], 128, "%s", dini_Get(file, "BR4")); format(DevBug[4][dBugs], 128, "%s", dini_Get(file, "BR5")); format(DevBug[5][dBugs], 128, "%s", dini_Get(file, "BR6")); format(DevBug[6][dBugs], 128, "%s", dini_Get(file, "BR7")); format(DevBug[7][dBugs], 128, "%s", dini_Get(file, "BR8")); format(DevBug[8][dBugs], 128, "%s", dini_Get(file, "BR9")); format(DevBug[9][dBugs], 128, "%s", dini_Get(file, "BR10")); format(DevBug[10][dBugs], 128, "%s", dini_Get(file, "BR11")); format(DevBug[11][dBugs], 128, "%s", dini_Get(file, "BR12")); format(DevBug[12][dBugs], 128, "%s", dini_Get(file, "BR13")); format(DevBug[13][dBugs], 128, "%s", dini_Get(file, "BR14")); format(DevBug[14][dBugs], 128, "%s", dini_Get(file, "BR15")); return 1; }
Please give +rep if I helped


Re: array index out of bounds - Facerafter - 09.07.2014

@Swalhalla .. what?

@David You only changed 1-15 to 0-14 ? And no doesn't work.

Ah I see what you guys mean now. But no, doesn't work.


Re: array index out of bounds - DavidSparks - 09.07.2014

Quote:
Originally Posted by Facerafter
View Post
@Swalhalla .. what?
I think my code is your answer to what he stated..


Re: array index out of bounds - ikkentim - 09.07.2014

Show your definition of dBugs.


Re: array index out of bounds - Sawalha - 09.07.2014

0 - 15 is the correct
pawn Code:
#define MAX_BUGS 16
new DevBug[MAX_BUGS][dBug];



Re: array index out of bounds - Facerafter - 09.07.2014

pawn Code:
enum dBugs
{
    dBug[128]
}
Sawalha, that may be. But it doesn't work.


Re: array index out of bounds - DavidSparks - 09.07.2014

Quote:
Originally Posted by Facerafter
View Post
pawn Code:
enum dBugs
{
    dBug[128]
}
Sawalha, that may be. But it doesn't work.
Did you try mine yet?


Re: array index out of bounds - Konstantinos - 09.07.2014

You had to use "dBug" in the format and not "dBugs". You don't need an enum for that if you're going to have only 1 string so:
pawn Code:
#define MAX_BUGS 16

new DevBug[MAX_BUGS][128];
pawn Code:
strcpy(DevBug[0], dini_Get(file, "BR1"), 128);
...
strcpy(DevBug[15],dini_Get(file, "BR15"), 128);
pawn Code:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)