SA-MP Forums Archive
Loop stalling server? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loop stalling server? (/showthread.php?tid=325594)



Loop stalling server? - 2KY - 13.03.2012

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?


Re: Loop stalling server? - Vince - 13.03.2012

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?


Re: Loop stalling server? - 2KY - 13.03.2012

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.