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_NAME[ MAX_PLAYER_NAME ],
USER_PASSWORD[ 129 ],
USER_ADMIN,
bool: USER_LOGGED_IN
};
new User[ MAX_PLAYERS ][ USER_DATA ];
public OnPlayerConnect( playerid )
{
for( new i; i < _: USER_DATA; ++i ) User[ playerid ][ USER_DATA: i ] = 0;
// ...
return 1;
}
2)
PHP код:
stock DB_Escape(text[])
{
new
ret[80* 2],
ch,
i,
j;
while ((ch = text[i++]) && j < sizeof (ret))
{
if (ch == '\'')
{
if (j < sizeof (ret) - 2)
{
ret[j++] = '\'';
ret[j++] = '\'';
}
}
else if (j < 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.