SA-MP Forums Archive
Store int value in an array - 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: Store int value in an array (/showthread.php?tid=636413)



Store int value in an array - iDark - 26.06.2017

I'm trying to store a value in an array but it doesn't work.

new Fish[MAX_PLAYERS][2];

At OnPlayerConnect I have Fish[playerid][0] = 0; and Fish[playerid][1] = 0;

In that 2 variables (I have 2 because a player can hold 2 fish) I want to store the type of fish which is from 0 to 9.
But when I try to store a fish type bigger than 1 I get:

[23:36:47] [debug] Run time error 4: "Array index out of bounds"
[23:36:47] [debug] Accessing element at index 2 past array upper bound 1

How can I store a value in that 2 fish variables?


Re: Store int value in an array - saffierr - 26.06.2017

Show us the code where you set the variables.


Re: Store int value in an array - iDark - 26.06.2017

Solved.
I had a function GetFishName(id) and I used it like GetFishName(Fish[playerid][id]) instead of GetFishName(id).