#Optimization of Animation Loop for Button Icon Transparency (DashBoard script)

7 messages · Page 1 of 1 (latest)

hollow linden
#

In the current script, the animation loop for the button icon transparency runs repeatedly even when the element is not visible, leading to unnecessary CPU load. This optimization has been made to calculate the animation only when the element is visible.
I’m learning scripting, so it’s possible that I’m wrong.

Before:

task.spawn(function()
local elapsed = 1
while dashboard and dashboardButton and dashboard._instance do
if not dashboard._instance.Visible then
elapsed = 1
end
local alpha = math.abs(elapsed % 2 - 1) * 0.7
dashboardButtonIcon.ImageTransparency = -(math.cos(math.pi * alpha) - 1) / 2
elapsed += task.wait()
end
end)

After

task.spawn(function()
local elapsed = 1
while dashboard and dashboardButton and dashboard._instance do
if dashboard._instance.Visible then
local alpha = math.abs(elapsed % 2 - 1) * 0.7
dashboardButtonIcon.ImageTransparency = -(math.cos(math.pi * alpha) - 1) / 2
end
elapsed += task.wait()
end
end)

hollow linden
#

I forgot to say , it's in the line 108:

hollow linden
#

( @hexed fable ) Just bumping this, I saw you liked the suggestion, but I haven’t heard back yet.

hexed fable
#

I've been busy focusing on more severe issues lately 😔

hollow linden
hollow linden