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=289561)

BeNq! 10-24-2016 16:50

Run time error 4: index out of bounds
 
2 Attachment(s)
Hello,

This is problem function:

Code:

ncod_setUserStatist(id, NCODSTATIST_HEALTH, 20)
Code:


L 10/24/2016 - 22:49:09: Start of error session.
L 10/24/2016 - 22:49:09: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20161024.log")
L 10/24/2016 - 22:49:09: [AMXX] Displaying debug trace (plugin "NCodMod_engine.amxx")
L 10/24/2016 - 22:49:09: [AMXX] Run time error 4: index out of bounds
L 10/24/2016 - 22:49:09: [AMXX]    [0] NCodMod_engine.sma::nativeSetUserStatist (line 1244)
L 10/24/2016 - 22:49:09: Unhandled dynamic native error
L 10/24/2016 - 22:49:09: [AMXX] Displaying debug trace (plugin "ncod_class_cybersuit.amxx")
L 10/24/2016 - 22:49:09: [AMXX] Run time error 10: native error (native "ncod_setUserStatist")
L 10/24/2016 - 22:49:09: [AMXX]    [0] ncod_class_cybersuit.sma::ncod_classChangeState (line 53)

Why? Please help me.

Natsheh 10-24-2016 17:40

Re: Run time error 4: index out of bounds
 
Its common error happens due passing index into native which the passed index is not in bound

BeNq! 10-24-2016 18:17

Re: Run time error 4: index out of bounds
 
How to fix?

BeNq! 10-25-2016 09:16

Re: Run time error 4: index out of bounds
 
Please help me.

BeNq! 10-26-2016 13:57

Re: Run time error 4: index out of bounds
 
Where is bug? Run time error 4: index out of bounds.

BeNq! 10-26-2016 18:56

Re: Run time error 4: index out of bounds
 
Code:

Code:

// ncod_getUserStats( id, NCodStatist: iStatist )
public nativeGetUserStatist( iPlugin, iParams )
{
        if( iParams != 2 )
        {
                new szPlugin[ 2 ][ 64 ];
                get_plugin( iPlugin, szPlugin[ 0 ], 63, szPlugin[ 1 ], 63 );
               
                log_amx( "[ %s < %s > ]: Blad przy pobieraniu wartosci statystyki!", szPlugin[ 1 ], szPlugin[ 0 ] );
                return -1;
        }
       
        return gPlayerInfo[ get_param( 1 ) ][ playerInfo: giStatistics[ NCodStatist: get_param( 2 ) ] ];
}

// ncod_setUserStats( id, NCodStatist: iStatist, iValue )
public nativeSetUserStatist( iPlugin, iParams )
{
        if( iParams != 3 )
        {
                new szPlugin[ 2 ][ 64 ];
                get_plugin( iPlugin, szPlugin[ 0 ], 63, szPlugin[ 1 ], 63 );
               
                log_amx( "[ %s < %s > ]: Blad przy pobieraniu wartosci statystyki!", szPlugin[ 1 ], szPlugin[ 0 ] );
                return -1;
        }
       
        if( any: get_param( 2 ) != NCODSTATIST_LEVEL )
                gPlayerInfo[ get_param( 1 ) ][ playerInfo: giStatistics[ NCodStatist: get_param( 2 ) ] ] = get_param( 3 );
        else
        {
                gPlayerInfo[ get_param( 1 ) ][ playerInfo: giStatistics[ NCODSTATIST_EXPERIENCE ] ] = power( get_param( 3 ), 2 ) * gPluginInfo[ plExperienceMultiplier ];
                gPlayerInfo[ get_param( 1 ) ][ playerInfo: giStatistics[ NCODSTATIST_LEVEL ] ] = get_param( 3 );
        }
       
        return 0;
}

Error with:
Code:

gPlayerInfo[ get_param( 1 ) ][ playerInfo: giStatistics[ NCodStatist: get_param( 2 ) ] ] = get_param( 3 );
Code:

return gPlayerInfo[ get_param( 1 ) ][ playerInfo: giStatistics[ NCodStatist: get_param( 2 ) ] ];

Bugsy 10-26-2016 19:47

Re: Run time error 4: index out of bounds
 
Edited to eliminate warnings in 1.8.2:
PHP Code:

// ncod_getUserStats( id, NCodStatist: iStatist )
public nativeGetUserStatistiPluginiParams )
{
    new 
iParam1 get_param);
    new 
iParam2 get_param);
    new 
szPlugin][ 64 ];
    
    if( 
iParams != )
    {
        
get_pluginiPluginszPlugin], 63szPlugin], 63 );
        
log_amx"[ %s < %s > ]: Blad przy pobieraniu wartosci statystyki!"szPlugin], szPlugin] );
        return -
1;
    }
    else if ( ( 
iParam1 >= sizeofgPlayerInfo ) ) || ( iParam2 >= sizeofgiStatistics ) ) || ( giStatisticsiParam2 ] >= sizeofgPlayerInfo[] ) ) )
    {
        
get_pluginiPluginszPlugin], 63szPlugin], 63 );
        
log_amx"[ %s < %s > ]: Bad param values!"szPlugin], szPlugin] );
        return -
1;    
    }
        
    return 
gPlayerInfoiParam1 ][ playerInfogiStatisticsiParam2 ] ];
}

// ncod_setUserStats( id, NCodStatist: iStatist, iValue )
public nativeSetUserStatistiPluginiParams )
{
    new 
iParam1 get_param);
    new 
iParam2 get_param);
    new 
szPlugin][ 64 ];
    
    if( 
iParams != )
    {
        
get_pluginiPluginszPlugin], 63szPlugin], 63 );
        
log_amx"[ %s < %s > ]: Blad przy pobieraniu wartosci statystyki!"szPlugin], szPlugin] );
        return -
1;
    }
    else if ( ( 
iParam1 >= sizeofgPlayerInfo ) ) || ( iParam2 >= sizeofgiStatistics ) ) || ( giStatisticsiParam2 ] >= sizeofgPlayerInfo[] ) ) )
    {
        
get_pluginiPluginszPlugin], 63szPlugin], 63 );
        
log_amx"[ %s < %s > ]: Bad param values!"szPlugin], szPlugin] );
        return -
1;    
    }

    if( 
anyget_param) != NCODSTATIST_LEVEL )
    {
        
gPlayerInfoiParam1 ][ playerInfogiStatisticsiParam2 ] ] = get_param);
    }
    else
    {
        
gPlayerInfoiParam1 ][ playerInfogiStatisticsNCODSTATIST_EXPERIENCE ] ] = powerget_param), ) * gPluginInfoplExperienceMultiplier ];
        
gPlayerInfoiParam1 ][ playerInfogiStatisticsNCODSTATIST_LEVEL ] ] = get_param);
    }
    
    return 
0;



BeNq! 10-27-2016 19:27

Re: Run time error 4: index out of bounds
 
"Tag mismatch":

Code:

else if ( ( iParam1 >= sizeof( gPlayerInfo ) ) || ( iParam2 >= sizeof( giStatistics ) ) || ( giStatistics[ iParam2 ] >= sizeof( gPlayerInfo[] ) ) )
Code:

else if ( ( iParam1 >= sizeof( gPlayerInfo ) ) || ( iParam2 >= sizeof( giStatistics ) ) || ( giStatistics[ iParam2 ] >= sizeof( gPlayerInfo[] ) ) )

Bugsy 10-27-2016 19:40

Re: Run time error 4: index out of bounds
 
Try this
PHP Code:

else if ( ( iParam1 >= sizeofgPlayerInfo ) ) || ( iParam2 >= sizeofgiStatistics ) ) || ( _:giStatisticsiParam2 ] >= sizeofgPlayerInfo[] ) ) ) 


BeNq! 11-03-2016 08:24

Re: Run time error 4: index out of bounds
 
Nope, "Tag mistmatch".


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

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