What does Theses "Loops" Means?
#1

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.
Reply
#2

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)