[Snippet / Function] Append Zero To Number Below 10

just started with Lua programming and i wanted to display a track-list and instrument-list in my tool. that was working fine, but i wanted it to display the way it does in the hydra (etc) popup/dropdown menus, so instead of


i wanted

01: Track01  
02: Kick  
03: Snare  
04: Track03  

the track-indexes obviously don’t have a appended 0, but just give you ‘1’ for Track01. so, i wrote a tiny function to do that. i figured others might want to use such a thing, so here it is.

-- custom function to append a zero to a number below 10  
function append_zero(value)  
 if value < 10 then  
 value = "0"..value  
 return value  
local value = 9  
local padded_string = string.format('%02d', value)  


damn, that’s even shorter!

well, at least there’s something to say for writing your own function when you’re having trouble finding it in the docs :)