well okay here goes, though it might be unnecessary I think I know what’s going on, see below.
[details=“Click to view contents”] ```lua
local options = renoise.Document.create {
show_debug_prints = true,
preset = {
" default preset"
},
tabletwo = {
" not a random number "
}
}
renoise.tool().preferences = options
– this always shows one – preferences not yet “ready” during loading?
renoise.app():show_error(options.preset:size() … ’ presets loaded.’) if options.preset:size() > 0 then renoise.app():show_error('last preset: ’ … options.preset[options.preset:size()].value) end
– this shows the correct amount
renoise.tool():add_menu_entry {
name = “Main Menu:Tools:show count & last entry”,
invoke = function()
renoise.app():show_error(options.preset:size() … ’ presets.’) if options.preset:size() > 0 then renoise.app():show_error('last preset: ’ … options.preset[options.preset:size()].value) end
end
}
renoise.tool():add_menu_entry {
name = “Main Menu:Tools:Add 3 table entries”,
invoke = function()
renoise.app():show_error(options.preset:size() … ’ presets before adding.’) if options.preset:size() > 0 then renoise.app():show_error(‘last preset: ’ … options.preset[options.preset:size()].value) end
options.preset:insert(“add1”)
options.preset:insert(“add2”)
options.preset:insert(“add3”)
renoise.app():show_error(options.preset:size() … ’ presets after adding.’) if options.preset:size() > 0 then renoise.app():show_error('last preset: ’ … options.preset[options.preset:size()].value) end
end
}
renoise.tool():add_menu_entry {
name = “Main Menu:Tools:Remove 2 entries”,
invoke = function()
renoise.app():show_error(options.preset:size() … ’ presets before removing.’) if options.preset:size() > 0 then renoise.app():show_error(‘last preset: ’ … options.preset[options.preset:size()].value) end
if options.preset:size() > 0 then options.preset:remove() end
if options.preset:size() > 0 then options.preset:remove() end
renoise.app():show_error(options.preset:size() … ’ presets after removing.’) if options.preset:size() > 0 then renoise.app():show_error('last preset: ’ … options.preset[options.preset:size()].value) end
end
}
renoise.tool():add_menu_entry {
name = “Main Menu:Tools:Change Tabletwo Entry”,
invoke = function()
renoise.app():show_error(options.tabletwo[1].value … ’ \n before.’)
options.tabletwo[1].value = tostring(math.random(1000))
renoise.app():show_error(options.tabletwo[1].value … ’ \n after.’)
end
}
renoise.tool():add_menu_entry {
name = “Main Menu:Tools:Toggle”,
selected = function() return options.show_debug_prints.value end,
invoke = function()
options.show_debug_prints.value = not options.show_debug_prints.value
end
}
it might not be a bug, but it surely confused me that [b]at startup[/b] the default table gets reported (in the example, size() is always 1, even after having added entries). that's what made me think and report that "it doesn't get updated".
querying it [b]after startup[/b] gives the expected results and also and reflects what gets saved into preferences.xml. I guess it's better to do the init stuff when the *dialog* gets called...
and that is what's confused me, I copied the tables values at startup, when the preferences are still at "default", and then in the running dialog I would only get those default presets obviously.
it couldn't hurt to mention that in the scripttool docs?
I was also wrong in that the "preferences go poof", it's just the [i]table[/i] that goes poof and gets recreated. You can use the provided script to try that out, or you can believe me and check it out yourself ^^
I guess the XML writer thing is just overzealous with saving space, so it drops the whole table and at startup that is not an "empty table", but "no table".
but empty table is a valid thing to have, right? otherwise that should be mentioned somewhere, too.