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.