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=600713)



Array Index Out Of Bounds - Dokins - 12.02.2016

Confused by this error. It's returning in the server log (server console). When I use the function.

The line is where the loop starts as in the first line after the for.

I've had to attach pictures since my internet went down!


Please see attached.

I'm making it so anytime a 911 call is placed they move up on the police computer I.e a new call equals 0 so the old 0 should move to slot 1.



Re: Array Index Out Of Bounds - -CaRRoT - 12.02.2016

Can you actually upload a proper picture or even an attachment ? There is no possible way to see that image.


Re: Array Index Out Of Bounds - Dokins - 12.02.2016

Updated!


Re: Array Index Out Of Bounds - Gammix - 12.02.2016

Probably you are passing an higher index than the maximum value in PoliceCall array.

What is the size of PoliceCall?

Check if its greater than 16 as your loop has max value of 15 and since you +1, it passes 16.


Re: Array Index Out Of Bounds - Dokins - 12.02.2016

It has a maximum value of 15; I don't think that is the case. Because I'm adding the +1 onto the x and not looping it. Unless I'm missing something.


Re: Array Index Out Of Bounds - Gammix - 12.02.2016

Quote:
Originally Posted by Dokins
Посмотреть сообщение
It has a maximum value of 15; I don't think that is the case. Because I'm adding the +1 onto the x and not looping it. Unless I'm missing something.
Thats actually the problem, your loop will have a maximum value of 15 (since x < 16).

So your code is
pawn Код:
PoliceCall[x + 1][..]
Which actually is (in the last case of loop)
pawn Код:
PoliceCall[15 + 1][..]
So you see you are passing 16 over there where the maximum number it can have is 15.

The loop should be:
pawn Код:
for (new x; x < 15; x++)
(so 14 + 1 = 15, which your array can have)


Also your code is wrong, since you are adding a new entry in index 0 and then saving all the data in +1 index through loops, but you forgot that you are also moving index 0 data to 1.
So basically the new entry will be copied to index 0 and 1. (both will have the same text)

You should run the loop first and then add a new entry to slot 0.


Re: Array Index Out Of Bounds - N0FeaR - 12.02.2016

Why take a pic with ur mobile lol can't u just upload the code on pastebin or something..


Re: Array Index Out Of Bounds - Dokins - 12.02.2016

I'm adding a new slot before I run the loop, I don't think that's the issue.