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

Fuck For Fun 08-18-2014 13:48

Run time error 4: index out of bounds
 
Quote:

L 08/19/2014 - 03:07:02: [AMXX] Displaying debug trace (plugin "Days.amxx")
L 08/19/2014 - 03:07:02: [AMXX] Run time error 4: index out of bounds
L 08/19/2014 - 03:07:02: [AMXX] [0] Days.sma::CmdVoteMenu_Handler
Code:

public CmdShowVoteMenu()
{
    static szMenu[ 100 ], iMenu, iTotalVotes;
   
    iTotalVotes = GetTotalVotes();
   
    formatex( szMenu, charsmax( szMenu ), "\r[%s] \yDays Vote  \wMenu^n^n\r// \wTime Left: \y%i Seconds^n\w\r// \wTotal Votes: \y%i  Votes", g_szMenuPrefix, g_iCounter, iTotalVotes );
   
    iMenu = menu_create( szMenu, "CmdVoteMenu_Handler" );
   
    for ( new i = 0; i < sizeof g_iSelectedDays; i++ )
    {
        formatex( szMenu, charsmax( szMenu ), "\w%s \r[\y%i Votes -  %i%s\r]", g_szDaysData[ g_iSelectedDays[ i ] ][ m_DayName ], g_iVotes[ i  ], (iTotalVotes > 0 ) ? ( floatround( ( float( g_iVotes[ i ] ) /  float( iTotalVotes ) ) * 100 ) ) : 0, "%" );
       
        menu_additem( iMenu, szMenu );
    }
   
    for ( new i = 0; i < g_iMaxPlayers; i++ )
    {
        if ( !is_user_connected( i ) )
            continue;
           
        menu_display( i, iMenu, 0 );
    }
}

public CmdVoteMenu_Handler( client, iMenu, item )
{
    if ( item != MENU_EXIT && is_user_connected( client ) )
    {
        if ( !g_iCounter )
            return 1;
   
        if ( g_iPlayersVotes[ client ] != DAY_NONE )
            return 1;
           
        g_iPlayersVotes[ client ] = g_iSelectedDays[ item ];
       
        g_iVotes[ item ]++;
       
        ColorChat( 0, RED, "%s^x03 %s^x01 has voted to^x04 %s^x01.",  g_szPrefix, GetUserName( client ), g_szDaysData[ g_iSelectedDays[ item ]  ][ m_DayName ] );
    }
   
    return 1;
}


HamletEagle 08-18-2014 14:11

Re: Run time error 4: index out of bounds
 
1. Don't do a players loop like this. Use get_players.
2. Maybe you shoud check is player is connected/alive.

Fuck For Fun 08-18-2014 14:30

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

Originally Posted by HamletEagle (Post 2185871)
1. Don't do a players loop like this. Use get_players.
2. Maybe you shoud check is player is connected/alive.

where check player connected/alive?

Give me another option to loop that I always use that.

HamletEagle 08-18-2014 14:40

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

Originally Posted by HamletEagle (Post 2185871)
1. Don't do a players loop like this. Use get_players.
2. Maybe you shoud check is player is connected/alive.

In bold, what you asked.

Fuck For Fun 08-18-2014 14:47

Re: Run time error 4: index out of bounds
 
Does not seem to me, to do check alive player's to votedays.

i set Connected and I will check it..

And as for CmdGgDay I have no idea ..

HamletEagle 08-18-2014 14:51

Re: Run time error 4: index out of bounds
 
Code:
public CmdVoteMenu_Handler( client, iMenu, item ) {     if ( item != MENU_EXIT && is_user_connected( id ) )     {         if ( !g_iCounter )             return 1;             if ( g_iPlayersVotes[ client ] != DAY_NONE )             return 1;                     g_iPlayersVotes[ client ] = g_iSelectedDays[ item ];                 g_iVotes[ item ]++;                 ColorChat( 0, RED, "%s^x03 %s^x01 has voted to^x04 %s^x01.", g_szPrefix, GetUserName( client ), g_szDaysData[ g_iSelectedDays[ item ] ][ m_DayName ] );     }         return 1; }

For 1:
Code:
new iPlayers[ 32 ], iNum get_players( iPlayers, iNum ) for( new i = 0; i < iNum; i++ ) { }

Fuck For Fun 08-18-2014 20:15

Re: Run time error 4: index out of bounds
 
post in thread

fysiks 08-19-2014 01:23

Re: Run time error 4: index out of bounds
 
Did you check the values that are being used to index ALL of the arrays in your function which is causing the errors?

Deathknife 08-19-2014 03:49

Re: Run time error 4: index out of bounds
 
This won't fix your problem, but shouldn't
Code:

g_iCurrentDay = g_iSelectedDays[ random( sizeof g_iSelectedDays ) ];
be:
Code:

g_iCurrentDay = g_iSelectedDays[ random( charsmax(g_iSelectedDays) ) ];

Flick3rR 08-19-2014 11:02

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

Originally Posted by Deathknife (Post 2186087)
This won't fix your problem, but shouldn't
Code:

g_iCurrentDay = g_iSelectedDays[ random( sizeof g_iSelectedDays ) ];
be:
Code:

g_iCurrentDay = g_iSelectedDays[ random( charsmax(g_iSelectedDays) ) ];

No.


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

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