Loop stalling server?
#1

I've created this command to go back into the folder, and read all of the reports backwards (newest being the most 'recent'), however, it only shows report 0 (which it does properly), and then stalls the server.

pawn Код:
CMD:checkreports( playerid, params[] )
{
    #pragma unused params
    new
        String[ 128 ],
        rePath[ 32 ];
       
    if( IsPlayerAdmin( playerid ) )
    {
        for( new re; re < FindLastReportID( ); re-- )
        {
            format( rePath, sizeof( rePath ), "Logs/Reports/Report%d.ini", re );
            if(fexist( rePath ) )
            {
                INI_ParseFile( rePath, "LoadReports_%s", .bExtra = true, .extra = re);
                format( String, sizeof( String ), "[R#%d (%s)] %s: "#WHITE"%s", re, reportInfo[ re ][ ReportTime ], reportInfo[ re ][ Reporter ], reportInfo[ re ][ ReportText ] );
                SendClientMessage( playerid, c_LIME, String );
            }
        }
    }
    return true;
}
Can anyone see what's wrong?
Reply
#2

Ye, infinite loop obviously.

Код:
assume FindLastReportID is 1
re is initialized to 0
0 smaller than 1
loop runs
re is decremented 
re is now -1
-1 still smaller than 1
loop runs
re is decremented
re is now -2
-2 still smaller than 1
loop runs
...
Get the point?
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Ye, infinite loop obviously.

Код:
assume FindLastReportID is 1
re is initialized to 0
0 smaller than 1
loop runs
re is decremented 
re is now -1
-1 still smaller than 1
loop runs
re is decremented
re is now -2
-2 still smaller than 1
loop runs
...
Get the point?
Yeah, thanks. I didn't think about that, I think I'm braindead today, lol.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)