AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Run time error 4: index out of bounds (https://forums.alliedmods.net/showthread.php?t=240779)

faki 05-22-2014 05:15

Run time error 4: index out of bounds
 
I have this:
Code:

#define TOTALLEVELS 12

new gEnt

new const Levels[TOTALLEVELS] =
{
0,
50,
100,
200,
300,
500,
750,
1000,
1250,
1500,
1750,
2000
}
new const LevelNames[TOTALLEVELS][] =
{
"NewBie",
"Beginner",
"Learning",
"Advanced",
"Ultimate",
"Kniffer",
"Killer",
"freak",
"PRO",
"Veteran",
"Respected",
"Matrix"
}

and this:
Code:

if( get_user_points(id) >= Levels[gLevel[id]] )
{
gLevel[id]++;
}

The line that makes the error is:
Code:

if( get_user_points(id) >= Levels[gLevel[id]] )
Its over the 2000 and makes the index out of bounds errors.
How to fix and if points of user is over 2000 to make last level without index out of bounds?

Flick3rR 05-22-2014 05:56

Re: Run time error 4: index out of bounds
 
Use a while loop. :) Like this:
PHP Code:

while( get_user_points(id) >= Levels[gLevel[id]] )
{
     
gLevel[id]++;



faki 05-22-2014 06:03

Re: Run time error 4: index out of bounds
 
not working.

Flick3rR 05-22-2014 06:23

Re: Run time error 4: index out of bounds
 
Maybe you will post the whole code. And for this while loop, it's just better when you are trying to increase variable in that way, depending on const. :)

Black Rose 05-22-2014 14:53

Re: Run time error 4: index out of bounds
 
Code:
if ( get_user_points(id) >= Levels[gLevel[id]] && gLevel[id] < TOTALLEVELS )     gLevel[id]++;


All times are GMT -4. The time now is 09:38.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.