How do I optimize overlays?

When I create an overlay, it looks something like this.

local diffusion = {
{ value = 0, label = “0.0%” },
{ value = 1, label = “4.0%” },
{ value = 2, label = “8.0%” },
{ value = 3, label = “12.0%” },
{ value = 4, label = “16.0%” },
{ value = 5, label = “20.0%” },
{ value = 6, label = “24.0%” },
{ value = 7, label = “28.0%” },
{ value = 8, label = “32.0%” },
{ value = 9, label = “36.0%” },
{ value = 10, label = “40.0%” },
{ value = 11, label = “44.0%” },
{ value = 12, label = “48.0%” },
{ value = 13, label = “52.0%” },
{ value = 14, label = “56.0%” },
{ value = 15, label = “60.0%” },
{ value = 16, label = “64.0%” },
{ value = 17, label = “68.0%” },
{ value = 18, label = “72.0%” },
{ value = 19, label = “76.0%” },
{ value = 20, label = “80.0%” },
{ value = 21, label = “84.0%” },
{ value = 22, label = “88.0%” },
{ value = 23, label = “92.0%” },
{ value = 24, label = “96.0%” },
{ value = 25, label = “100.0%” }
}

overlays.create(1, diffusion)

Can I somehow optimize this by making an array where only the following text is present?

array = {“0.0%”, “4.0%”, “8.0%”, “12.0%” ,“16.0%”, “20.0%”, “24.0%”, “28.0%”}
and so on…

What should the lua code look like to make this an overlay?

as it looks very linear, you can do this:

local myList = {}

for i = 0, 25 do
    table.insert(myList, { value = i, label = (i * 4) .. "%" })
end
1 Like

Thanks a lot Martin. You are the best.

you can also do it with a format function like this:

function fmtDiffusion(valueObject, value)
   return string.format("%d %%", math.floor(value * 4))
end

where the function is attached to the control here:
diffusion

4 Likes