AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved]Index out of bounds (https://forums.alliedmods.net/showthread.php?t=132302)

#8 SickneSS 07-13-2010 17:50

[Solved]Index out of bounds
 
Code:

L 07/13/2010 - 18:27:05: [AMXX] Run time error 4: index out of bounds
L 07/13/2010 - 18:27:05: [AMXX] [0] Mix_Maker.sma::cmdSayRestart (line 930)

PHP Code:

public cmdSayRestart(id,level,cid) {
    
    if(!
cmd_access(id,level,cid,1))
        return 
PLUGIN_HANDLED
    
    
new said[192]
    
read_args(said,191)
    
remove_quotes(said)
    
    if(!
strlen(said) || said[0] == ' ')
        return 
PLUGIN_HANDLED
        
    
new name[32]
    
get_user_name(id,name,31)
    
    new 
Restart[11]
    new 
Tmp[11]
    
strbreak(said,Restart,10,Tmp,10)
    
    new 
Value str_to_num(Tmp)

    new const 
Restrts[][] = 
    { 
        
"/restart","!restart",".restart",
        
"/rr","!rr",".rr",
        
"/r","!r",".r" 
    
}
    
    for(new 
0;<= sizeof (Restrts);i++)
    {
        if(
equali(Restart,Restrts[i]))
        {
            if(!
is_str_num(Tmp) || Value 60)
                
Value 1
                    
            
if(!Tmp[0])
                
set_pcvar_num(pRestart,1)
            else
                
set_pcvar_num(pRestart,Value)
                
            
ChatColor(0,"%s !yADMIN %s : Restarteo la ronda",szPrefix,name)
            return 
PLUGIN_HANDLED
        
}
    }
    return 
PLUGIN_CONTINUE



fysiks 07-13-2010 17:59

Re: Index out of bounds
 
You need to learn that it's much much easier if we know what line is the line referenced in the error.

The error is cause by the <= in the for loop. Must be only <.

#8 SickneSS 07-13-2010 17:59

Re: Index out of bounds
 
Quote:

Originally Posted by fysiks (Post 1238195)
You need to learn that it's much much easier if we know what line is the line referenced in the error.

PHP Code:

        if(equali(Restart,Restrts[i])) 

I trying searching the same error in others plugins,but I can't find the solution.

fysiks 07-13-2010 18:01

Re: Index out of bounds
 
Found the error, read above.

#8 SickneSS 07-13-2010 18:06

Re: Index out of bounds
 
If I change that the command doesn't works

Bugsy 07-13-2010 18:24

Re: Index out of bounds
 
Quote:

Originally Posted by fysiks (Post 1238195)
You need to learn that it's much much easier if we know what line is the line referenced in the error.

The error is cause by the <= in the for loop. Must be only =

<

Alucard^ 07-13-2010 18:33

Re: Index out of bounds
 
I think fysiks wanted to say "<"

PHP Code:

for(new 0;sizeof (Restrts);i++) 

You have to remember that the last number of the array size is null... so if you use "<=" you use Restrts[9] and you should use at Restrt[8] (9 is null).

Bugsy 07-13-2010 18:38

Re: Index out of bounds
 
Quote:

Originally Posted by Alucard^ (Post 1238233)
I think fysiks wanted to say "<"

PHP Code:

for(new 0;sizeof (Restrts);i++) 

You have to remember that the last number of the array size is null... so if you use "<=" you use Restrts[9] and you should use at Restrt[8] (9 is null).

An array is sized with the number specified but elements are accessed with indexes starting at 0. The last element being null is really only with null terminated strings. Index out of bounds is telling you that your trying to reference memory that doesn't exist. If you size the array at 8 then the last element is 7.

Alucard^ 07-13-2010 18:41

Re: Index out of bounds
 
Emm yes i know that elements are accesed with indexes starting at 0, but i didn't understand this:

Quote:

The last element being null is really only with null terminated strings

Bugsy 07-13-2010 18:52

Re: Index out of bounds
 
An array can hold any values in every index. When an array holds a string, the last element is reserved for a null char to signify end of string


All times are GMT -4. The time now is 07:13.

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