Question about variables
#1

Do I have to check if variable's value is different before setting it?

Example

Code:
new bool:IsSpawned[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
	IsSpawned[playerid] = true;
	return 1;
}
or

Code:
new bool:IsSpawned[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
	if(IsSpawned[playerid] != true)
	{
		IsSpawned[playerid] = true;
	}
	return 1;
}
Which way is better? Or is there no difference?
Reply
#2

Quote:
Originally Posted by 2Col
View Post
Do I have to check if variable's value is different before setting it?

Example

Code:
new bool:IsSpawned[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
	IsSpawned[playerid] = true;
	return 1;
}
or

Code:
new bool:IsSpawned[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
	if(IsSpawned[playerid] != true)
	{
		IsSpawned[playerid] = true;
	}
	return 1;
}
Which way is better? Or is there no difference?
In that case, you don't need to. Still in that case, the first one is better : less code, faster compilation (some nanoseconds I guess lol).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)