What type of script entry is best to use?

What type of script writing do you think is better? Of course, it is absolutely clear that both scenarios will have such a small difference between themselves that it is not even noticeable, but if you use them very often it can affect the operation of the game as a whole.

Which of these two types is more productive and efficient?

A)

-- Example 1 (A)

local SpawnLocation = workspace.SpawnLocation

SpawnLocation.Size = Vector3.new(10, 2, 10)
SpawnLocation.Position = Vector3.new(10, 1, 10)
SpawnLocation.Rotation = Vector3.new(0, 45, 0)
SpawnLocation.BrickColor = BrickColor.new("Gold")
SpawnLocation.Transparency = .5

-- Example 2 (A)

local Time = "Day-1-12:00"
local TimeSplit = string.split(Time, "-")

local IsDoorOpened = false

if TimeSplit[1] == "Day" then
	
	if tonumber(TimeSplit[2]) > 2 then
		
		if tonumber(string.split(TimeSplit[3], ":")[1]) > 12 then
			IsDoorOpened = true
		end
		
	end
else
	
	if tonumber(TimeSplit[2]) >= 4 then
		IsDoorOpened = true
	end
	
end

B)

-- Example 1 (B)

workspace.SpawnLocation.Size = Vector3.new(10, 2, 10)
workspace.SpawnLocation.Position = Vector3.new(10, 1, 10)
workspace.SpawnLocation.Rotation = Vector3.new(0, 45, 0)
workspace.SpawnLocation.BrickColor = BrickColor.new("Gold")
workspace.SpawnLocation.Transparency = .5

-- Example 2 (B)

local Time = "Day-1-12:00"

local IsDoorOpened = false

if string.split(Time, "-")[1] == "Day" then
	
	if tonumber(string.split(Time, "-")[2]) > 2 then
		
		if tonumber(string.split(string.split(Time, "-")[3], ":")[1]) > 12 then
			IsDoorOpened = true
		end
		
	end
else
	
	if tonumber(string.split(Time, "-")[2]) >= 4 then
		IsDoorOpened = true
	end
	
end

In these two examples, we see that example A uses variables to store information, and in example B we do not use them, but go directly to the source.

Disadvantages (A):
Perhaps the server or client memory is clogged with a large number of variables and the game becomes slower.

Disadvantages (B):
Constantly performing any actions, for example “string.split()” wastes the performance of the server or client, which also slows down the game.


Now I want to know what is better to use for greater efficiency and minimization of inefficiency.

If you were really asking on what is “faster” and “better”, it’s A - since you’re making something you need to calculate a lot to a defined variable, which greatly reduces the amount of calculations. It’s also easier to read.

(The part below is unnecessary, it’s just if you want to see my opinion on it.)

In example 1 I prefer using A - honestly it doesn’t make a difference. One more variable doesn’t clog up any memory, even you’re using a thousand of them - which doesn’t seem like the best idea to fit all of them in one script. I just love A since it looks short and concise.

Also for example 2 I prefer using A aswell, since it’s shorter and it doesn’t clog everything up. Just look at this: tonumber(string.split(string.split(Time, "-")[3], ":")[1]) > 12. I wouldn’t even know what it is after 1 minute of looking.

1 Like

Thank you, your advice was very helpful!

1 Like