Little problem about arrays.
#1

[Problem solved : If you have some troubles using arrays, I would recommend this tutorial : https://sampforum.blast.hk/showthread.php?tid=318212
]


Hello everybody !

These days I'm looking on the U-RP Gamemode that was released, and I try to add 2 more ranks for factions, I mean that factions will now have 8 ranks, not 6 anymore, everything was great until I met arrays.

I compiled, and this is what I get :

Quote:

C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8861) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8862) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8870) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8871) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8879) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8880) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(888 : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8889) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8897) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(889 : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8906) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8907) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8915) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8916) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8924) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8925) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8933) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8934) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8942) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(8943) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9201 -- 9249) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9201 -- 925 : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9201 -- 9267) : error 032: array index out of bounds (variable "FactionRank")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9201 -- 9267) : fatal error 107: too many error messages on one line


Ok so for example let's take lines 8861-8862 (where I get the error !):
pawn Код:
strmid(FactionRank[1][7], arrCoords[46], 0, strlen(arrCoords[46]), 255);
        strmid(FactionRank[1][8], arrCoords[47], 0, strlen(arrCoords[47]), 255);
Now let's take the 6 lines before these 2 lines 8855-8860 :
pawn Код:
strmid(FactionRank[1][1], arrCoords[40], 0, strlen(arrCoords[40]), 255);
        strmid(FactionRank[1][2], arrCoords[41], 0, strlen(arrCoords[41]), 255);
        strmid(FactionRank[1][3], arrCoords[42], 0, strlen(arrCoords[42]), 255);
        strmid(FactionRank[1][4], arrCoords[43], 0, strlen(arrCoords[43]), 255);
        strmid(FactionRank[1][5], arrCoords[44], 0, strlen(arrCoords[44]), 255);
        strmid(FactionRank[1][6], arrCoords[45], 0, strlen(arrCoords[45]), 255);


What is the problem ?
Can someone explain to me how arrays really work in this case ?
What have I done wrong ?
How may I correct it ?
Do you have any tips to give to me about arrays ?

Thanks in advance.
Reply
#2

Well after many googling I can't really find any clear explanation about this. Some does ? Thanks.
Reply
#3

Keep in mind that array indices start at 0, not 1. That means if you have an array with 6 slots, you access them with indices 0 through 5.
Reply
#4

I try to understand what you're explaining, I just can't really imagine, can you please illustrate ?
Is the problem related to this ?

pawn Код:
new FactionRank[11][7][32];
I'm reading some tutorial about arrays, this a three dimensional one isn't it ? What can you tell me about it ?
Thanks for helping me.



EDIT :

pawn Код:
new FactionRank[11][7][32];
It must be changed to
pawn Код:
new FactionRank[11][9][32];
then ?


EDIT 2 :
Well the situation changed.

Now my errors are :
Quote:

C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9414) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9415) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9416) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9417) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9419) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9420) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9421) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9422) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9423) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9424) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9425) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9426) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(942 : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9429) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9430) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9431) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9432) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9433) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9434) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(9435) : error 032: array index out of bounds (variable "arrCoords")
C:\Users\Geo\Desktop\U-RP [ENG - 0.3x]\gamemodes\U-RP.pwn(29271) : warning 206: redundant test: constant expression is non-zero


I'll look for more informations about this.


EDIT 3 : I solved the problem by changing
pawn Код:
new arrCoords[60][512];
to
pawn Код:
new arrCoords[79][512];



Thanks a lot !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)