<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi all,<div><br></div><div>I am trying to write a program which calculates the slide positions for a trombone and calculates the total slide length for the selected notes. As there are some notes with alternative positions, I want to create a table where each row has a possible combination of positions. In column 0 there will be the total slide length per row, so I can find the combination with the smallest total slide length.</div><div>If there is an alternative position possible for a note, it creates new rows and copies the previous values. But for some reason, when I try to copy a cell in the next for-loop, that value is always nil, although it was filled in the previous loop...</div><div> </div><div>I am a total newbie to Lua and to some degree to programming in general, so I might not be doing this the most elegant way, but if I insert some print lines, the program does everything I want. So ugly as it might be, it works, it just doesn't seem to remember the values...</div><div><br></div><div>I have added the relevant code under this message. Any suggestions are appreciated!</div><div><br></div><div>All the best,</div><div><br></div><div>Emile</div><div><br></div><div><div>column = 1</div><div>totallength = 0</div><div>i = 1</div><div>c = 1</div><div>imax = 1</div><div>k = 1</div><div>for entry in eachentrysaved(finenv.Region()) do</div><div>    local highestnote = entry:CalcHighestNote(nil)</div><div>    if highestnote then</div><div>        midi = highestnote:CalcMIDIKey()</div><div>                -- the slide position is calculated, deleted here for clarity</div><div>                for i= 1, imax do</div><div>                    table[i]={}</div><div>                    table[i][c] = position</div><div>                    -- the slide length is calculated, deleted here for clarity</div><div>                    table[i][0] = totallength</div><div>                end</div><div><br></div><div>                if Alternation(midi) then -- determines if there is an alternative position</div><div>                    for k = imax+1, imax*2 do -- new rows are being created</div><div>                        table[k]={}</div><div>                        for d = 1, c-1 do -- and the input of the last rows is copied</div><div>                            table[k][d] = table[k-imax][d] -- this should copy the value of the previous rows to the new rows, but it always give a nil value...</div><div>                        end</div><div>                        -- the alternative position is calculated, deleted for clarity</div><div>                        table[k][c]= position -- here the new value is added</div><div>                        -- and the new length is calculated, deleted for clarity</div><div>                        table[trumpet][k][0] = totallength</div><div>                    end</div><div>                    imax = imax*2</div><div>                end</div><div>        end</div><div>    c = c + 1 -- end</div><div>end</div></div></div></div></div>