Raised This Month: $ Target: $400
 0% 

Run time error 4: index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
faki
Senior Member
Join Date: Jul 2013
Old 05-22-2014 , 05:15   Run time error 4: index out of bounds
Reply With Quote #1

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?

Last edited by faki; 05-22-2014 at 05:16.
faki is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-22-2014 , 05:56   Re: Run time error 4: index out of bounds
Reply With Quote #2

Use a while loop. Like this:
PHP Code:
while( get_user_points(id) >= Levels[gLevel[id]] )
{
     
gLevel[id]++;

__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
faki
Senior Member
Join Date: Jul 2013
Old 05-22-2014 , 06:03   Re: Run time error 4: index out of bounds
Reply With Quote #3

not working.
faki is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-22-2014 , 06:23   Re: Run time error 4: index out of bounds
Reply With Quote #4

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.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-22-2014 , 14:53   Re: Run time error 4: index out of bounds
Reply With Quote #5

Code:
if ( get_user_points(id) >= Levels[gLevel[id]] && gLevel[id] < TOTALLEVELS )     gLevel[id]++;
__________________

Last edited by Black Rose; 05-22-2014 at 14:53.
Black Rose is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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