# How do I optimize overlays?

**URL:** <https://forum.electra.one/t/how-do-i-optimize-overlays/2795>\
**Category:** Developers\
**Created:** [April 1, 2024, 3:36pm UTC](https://forum.electra.one/t/how-do-i-optimize-overlays/2795 "2024-04-01T15:36:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Electrolove](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/electrolove/32/2440_2.png) [@Electrolove](https://forum.electra.one/u/Electrolove)\
**Post date:** [April 1, 2024, 3:36pm UTC](https://forum.electra.one/t/how-do-i-optimize-overlays/2795/1 "2024-04-01T15:36:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)\
**Post date:** [April 1, 2024, 5:29pm UTC](https://forum.electra.one/t/how-do-i-optimize-overlays/2795/2 "2024-04-01T17:29:42Z")

</div>

as it looks very linear, you can do this:

```auto
local myList = {}

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

```

---

<div class="post-metadata">

**Author:** ![Electrolove](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/electrolove/32/2440_2.png) [@Electrolove](https://forum.electra.one/u/Electrolove)\
**Post date:** [April 1, 2024, 6:57pm UTC](https://forum.electra.one/t/how-do-i-optimize-overlays/2795/3 "2024-04-01T18:57:08Z")

</div>

Thanks a lot Martin. You are the best.

---

<div class="post-metadata">

**Author:** ![oldgearguy](https://avatars.discourse-cdn.com/v4/letter/o/f4b2a3/32.png) [@oldgearguy](https://forum.electra.one/u/oldgearguy)\
**Post date:** [April 1, 2024, 7:09pm UTC](https://forum.electra.one/t/how-do-i-optimize-overlays/2795/4 "2024-04-01T19:09:48Z")

</div>

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

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

```

where the function is attached to the control here:  
 ![diffusion](https://europe1.discourse-cdn.com/flex017/uploads/electraone/original/2X/1/14fa71b6d51d9cf7c787ff8920e29c09cc90b2be.jpeg)
