SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 07/07/2018, 03:51 PM   #1
2Col
Little Clucker
 
Join Date: Nov 2017
Posts: 21
Reputation: 0
Default 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?
2Col is offline   Reply With Quote
Old 08/07/2018, 04:13 AM   #2
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,927
Reputation: 256
Default Re: Question about variables

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).
__________________
actor_plus - v5.0.2
I'm a goner, somebody catch my breath,
I'm a goner, somebody catch my breath
Dayrion is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A question about variables ? FilesMAker Scripting Help 2 02/07/2015 11:25 PM
1 question about Variables AnonScripter Scripting Help 5 06/11/2013 11:30 AM
Question about Variables CoDeZ Scripting Help 8 02/08/2012 11:45 AM
Question about variables... Whizion Scripting Help 8 10/09/2011 07:42 PM
Question about variables blackwave Help Archive 3 07/01/2011 01:58 AM


All times are GMT. The time now is 03:41 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.