Avatar Chat example checking if user has changed position
Posted: 08 Feb 2012, 14:25
I am just going through the avatar chat example and am struggling to understand why the conditions in the if statement indicate that a user has changed position.
why would changedVars.indexOf(USERVAR_X) be equal to -1 if the variables had not changed?
code from the website:
// Check if the user changed his position
if (changedVars.indexOf(USERVAR_X) != -1 || changedVars.indexOf(USERVAR_Y) != -1)
{
// Check if avatar exists
if (getAvatar(user.id) != null)
{
// Move the user avatar
moveAvatar(user)
}
why would changedVars.indexOf(USERVAR_X) be equal to -1 if the variables had not changed?
code from the website:
// Check if the user changed his position
if (changedVars.indexOf(USERVAR_X) != -1 || changedVars.indexOf(USERVAR_Y) != -1)
{
// Check if avatar exists
if (getAvatar(user.id) != null)
{
// Move the user avatar
moveAvatar(user)
}