Question about variables - 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)
+---- Forum: Discussion (
https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: Question about variables (
/showthread.php?tid=656111)
Question about variables -
2Col - 07.07.2018
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?
Re: Question about variables -
Dayrion - 08.07.2018
Quote:
Originally Posted by 2Col
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).