array index out of bounds
#1

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!
Reply
#2

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)?
Reply
#3

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. 
Reply
#4

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.
Reply
#5

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...
Reply
#6

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

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.
Reply
#8

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)