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



array index out of bounds - Viggo - 02.04.2019

I have wrote a little code, and I'm getting the array index out of bound error, the error is because of the last line.

Link: https://pastebin.com/FfK57zcS

I have tried many things but error still appears. Please help!


Re: array index out of bounds - NaS - 02.04.2019

From the looks this seems unlikely to produce the error as you are accessing index 0 which is definitely not out of bounds.

Could you share the code where you use it (maybe a few lines before and after)?


Re: array index out of bounds - Logic_ - 02.04.2019

Isn't this wrong??

PHP код:
    wc_vehid = -1/// Just a default value. Don't change this.
    
bool:wc_locked false/// Whether the car is locked or no. It's unlocked in default, don't change this.
    
Text3D:wc_3dlabel = -1/// This is for attaching the "locked car" label into the car. It's -1 by default, don't change this. 



Re: array index out of bounds - Viggo - 02.04.2019

Quote:
Originally Posted by NaS
Посмотреть сообщение
From the looks this seems unlikely to produce the error as you are accessing index 0 which is definitely not out of bounds.

Could you share the code where you use it (maybe a few lines before and after)?
That pastebin is an include file, I copied the whole include and pasted it in the pastebin.

There is no much included before this include file, they are all like zcmd includes and stuff.


Re: array index out of bounds - JesterlJoker - 02.04.2019

PHP код:
#define MAX_WC 2

new wc_info[MAX_WC][weekendCars_Data]; 
I think it should look like that. On my own Opinion...

Like what NaS said it should not make an error like that, the only problem is that... Maybe the gamemode does not see this line of code as initialized properly...


Re: array index out of bounds - RedFusion - 02.04.2019

You can't initialize enumerators like that.
You need to assign a default value at runtime, preferrably at script init (OnGameModeInit / OnFilterScriptInit)


Re: array index out of bounds - Viggo - 02.04.2019

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
You can't initialize enumerators like that.
You need to assign a default value at runtime, preferrably at script init (OnGameModeInit / OnFilterScriptInit)
Okay, this is the full code: https://pastebin.com/Lg69bi9s

It's a filterscript, I compile, I get the "array index out of bounds" error at the last callback (commented next to the error line).

Fix this and reply here with the fixed version. Thanks alot.


Re: array index out of bounds - Viggo - 02.04.2019

Okay nvm fixed, the problem was in having those default values in the enum. Have no clue why it's buggy tho.


Re: array index out of bounds - TheToretto - 02.04.2019

Quote:
Originally Posted by Viggo
Посмотреть сообщение
Okay nvm fixed, the problem was in having those default values in the enum. Have no clue why it's buggy tho.
You can't assign default values to enums, instead use a loop when the gamemode starts, and assign every single array to whatever value you like.

pawn Код:
#define MAX_WEEKEND_CARS 50

public OnGameModeInit(){
    for(new i; i < MAX_WEEKEND_CARS; i++){
        wcInfo[i][wc_vehid] = -1;
        wcInfo[i][wc_3dlabel] = -1;
    }
    return 1;
}
And a boolean without a value is always false, no need to change that.