Raised This Month: $ Target: $400
 0% 

Strange problem "Run time error 4: index out of bounds"


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
FEELiFE
Member
Join Date: Jul 2010
Old 11-08-2011 , 14:01   Re: Strange problem "Run time error 4: index out of bounds"
Reply With Quote #3

Quote:
Originally Posted by Sylwester View Post
You get index out of bounds either on iPtz or item_cost

If you can't find the error yourself only with looking at the code and you can't post more code then you should start debugging it like this:
PHP Code:
 if(is_user_connected(id)) {
     if(
id >= sizeof iPtz)
         
log_amx("id value (%d) out of bounds, should be (0..%d)"idsizeof iPtz -1)
     if(
get_info >= sizeof item_cost || get_info 0)
         
log_amx("get_info value (%d) out of bounds, should be (0..%d)"get_infosizeof item_cost -1)
     
iPtz[id] -= item_cost[get_info];
 } 
It returns: get_info value (-3) out of bounds, should be (0..2)

I use negative values for exceptions like the user doesn't have enough money to buy an item or has already the item.

Here is the code:
PHP Code:
new access,callbackinfo[3], get_info;
    
menu_item_getinfo(menu,item,accessinfo,2_,_callback);
    
get_info str_to_num(info);
    
    switch(
get_info)
    {
        case -
4:
        {
            
some code..
        }
        case -
3:
        {
            
some code..
        }
        case -
2:
        {
           If 
already has the item..
        }
        case -
1:
        {
            
Not enough money..
    }
    
    if(
is_user_connected(id)) {
        if(
is_user_connected(id)) {
            if(
id >= sizeof iPtz) {
                
log_to_file(log_file"[Item] id value (%d) out of bounds, should be (0..%d)"idsizeof iPtz -1);
            }
            if(
get_info >= sizeof item_cost || get_info 0) {
                
log_to_file(log_file"[Item] get_info value (%d) out of bounds, should be (0..%d)"get_infosizeof item_cost -1);
            }
            
iPtz[id] -= item_cost[get_info];
            
item_level[id][get_info]++;
        }
        
show_items_menu(id);
    } 
And the items arrays:
PHP Code:
new const item_name[][] =
{
    
"Item1",
    
"Item2"
};

new 
item_level[33][sizeof(item_name)+1];

new const 
item_cost[sizeof(item_name)+1] =
{
    
80,
    
50
}; 
So any ideas?
FEELiFE is offline
 



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 14:20.


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