[Fixed 2.6 Beta] Scripting Preferences Xml Removes Does Not Restore Em

If I have a table of strings in the prefs document, created properly and stuff, resulting in a preferences.xml like this

stuff  
<preset><br>
    <preset_item>first preset</preset_item><br>
    <preset_item>second preset</preset_item><br>
  </preset>  
more stuff  

and then use remove() to remove them in the code, so the preset table is empty, the preferences get saved as

stuff  
more stuff  

upon exit. this in turn makes the validation think on the next startup that the prefs have to be recreated, so they get reset. I guess actually it should look like this

stuff  
<preset><br>
  </preset>  
more stuff  

?

It can be easily be worked around if you know about it, but it still seems like a bug.

when I add entries to a table in the preferences, they get saved in preferences.xml, but not loaded? let’s say I add a preset each time I run the script, then restart renoise - the entries get appended and look just like the others, but they don’t get loaded. it seems like only the original size of the table gets taken into account, not what is actually in the XML file.

local script_options = renoise.Document.create {  
 command_preset = {  
 " ",  
 "sox $1 $2 repeat 1",  
 etc.  
  
 }  
}  
  
renoise.tool().preferences = script_options  
script_options.command_preset:insert(tf_command_line.text)  

but script_options.command_preset:size() always returns the original value, and iterating past it throws the expected error… or do I have to somehow nest the documents? There is not much to go by, I really, really looked at the docs and examples, I made a test case that works for anything but tables that change the size… so I have to ask, and it might be a bug after all.

Would be great if you could provide a full example and not just some snippets. Hard to guess what’s wrong without seeing everything.

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.

Thanks for the info. Yes, thats indeed a problem. Will fix this for the next beta…