SA-MP Forums Archive
What does Theses "Loops" Means? - 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: What does Theses "Loops" Means? (/showthread.php?tid=582276)



What does Theses "Loops" Means? - TheRaGeLord - 19.07.2015

What does this loop means?

1)
PHP код:
enum USER_DATA
{
    
USER_ID,
    
USER_NAMEMAX_PLAYER_NAME ],
    
USER_PASSWORD129 ],
    
USER_ADMIN,
    
boolUSER_LOGGED_IN
};
new    
UserMAX_PLAYERS ][ USER_DATA ];
public 
OnPlayerConnectplayerid )
{
    for( new 
i_USER_DATA; ++Userplayerid ][ USER_DATA] = 0;
    
// ...
    
return 1;

2)
PHP код:
stock DB_Escape(text[])
{
    new
        
ret[802],
        
ch,
        
i,
        
j;
    while ((
ch text[i++]) && sizeof (ret))
    {
        if (
ch == '\'')
        {
            if (
sizeof (ret) - 2)
            {
                
ret[j++] = '\'';
                
ret[j++] = '\'';
            }
        }
        else if (
sizeof (ret))
        {
            
ret[j++] = ch;
        }
        else
        {
            
j++;
        }
    }
    
ret[sizeof (ret) - 1] = '\0';
    return 
ret;

Can anyone tell me that what does these both loops mean?
as I'm not able to understand them.


Re: What does Theses "Loops" Means? - Vince - 19.07.2015

The first one resets a player's data to 0. However, a (probably) more efficient way of doing that is:

PHP код:
static const emptyInfo[USER_DATA];
User[playerid] = emptyInfo
The second one escapes ' characters in a string for usage in SQL statements. It does this by checking each character separately and copying it to the output. Obsolete as of 0.3.7 R2 where the new format specifier %q fulfills this functionality.