SA-MP Mobile

SA-MP Scripting and Plugins => Scripting Help => Discussion => Topic started by: SA:MP on May 05, 2023, 08:51 AM

Title: Question about variables
Post by: SA:MP on May 05, 2023, 08:51 AM
Question about variables

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?

Source: Question about variables (https://sampforum.blast.hk/showthread.php?tid=656111)