[JW Lua] Tables getting reset?

Harald Schollmeyer hschollm at gmx.net
Wed Sep 16 14:14:02 CEST 2020


Hello Emile,

I wrote a similar script, maybe it‘s of some use:

https://forum.makemusic.com/default.aspx?f=11&m=474054

Best,

Harald


-- 
___________________________________
Harald Schollmeyer
Wesmarstr. 3a, 45659 Recklinghausen
Telefon: +4923614879188 und +491773125084
E-Mail: hschollm at gmx.net

> Am 16.09.2020 um 13:49 schrieb Emile Meuffels <e.meuffels at gmail.com>:
> 
> 
> Hi all,
> 
> 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.
> 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...
>  
> 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...
> 
> I have added the relevant code under this message. Any suggestions are appreciated!
> 
> All the best,
> 
> Emile
> 
> column = 1
> totallength = 0
> i = 1
> c = 1
> imax = 1
> k = 1
> for entry in eachentrysaved(finenv.Region()) do
>     local highestnote = entry:CalcHighestNote(nil)
>     if highestnote then
>         midi = highestnote:CalcMIDIKey()
>                 -- the slide position is calculated, deleted here for clarity
>                 for i= 1, imax do
>                     table[i]={}
>                     table[i][c] = position
>                     -- the slide length is calculated, deleted here for clarity
>                     table[i][0] = totallength
>                 end
> 
>                 if Alternation(midi) then -- determines if there is an alternative position
>                     for k = imax+1, imax*2 do -- new rows are being created
>                         table[k]={}
>                         for d = 1, c-1 do -- and the input of the last rows is copied
>                             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...
>                         end
>                         -- the alternative position is calculated, deleted for clarity
>                         table[k][c]= position -- here the new value is added
>                         -- and the new length is calculated, deleted for clarity
>                         table[trumpet][k][0] = totallength
>                     end
>                     imax = imax*2
>                 end
>         end
>     c = c + 1 -- end
> end
> _______________________________________________
> JWLua mailing list
> JWLua at jwmusic.nu
> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20200916/04b366c7/attachment.html>


More information about the JWLua mailing list