Another day, another lua question.
Iām wondering if folks have tips for modifying the range of a for loop dynamically, or if such a thing is even possible. 
For context, I originally had a function - newPattern() - that created a new 16-step note pattern in my recent script, Patchwork. Itās called from init, but it can also be called via a special command at any point by the user. Works great as is:
function newPattern()
for i=1,16 do
table.insert(pattern[1], i, math.random(8))
end
end
Iāve since been experimenting with new variables that let you change the start and end points of the sequence with the encoders (which also works great)ā¦
local seqStart = 1
local seqEnd = 16
ā¦which naturally led me to updating my newPattern() function accordingly:
function newPattern()
for i=seqStart,seqEnd do
table.insert(pattern[1], i, math.random(8))
end
end
The weird thing - and this may very well be due to my limited knowledge of for loops - is that this modified function works great, but when I change the seqStart and seqEnd values and then call newPattern() again, the loop iterates from seqStart (cool) to 16 when Iād expect it to stop at whatever seqEnd is set as. Basically, I just want new values inserted within the new range set by seqStart and seqEnd.
Does this make any sense? Itās been driving me a little nuts because half of it works as expected. I suspect thereās some fundamental thing Iām missingā¦