Scripting help? How to get chosen file path to effect the default entry for the next one?

local PACKED = "p"
local AJSON "j"
local infered_json_filename = nil
dlg:file{
    id = PACKED,
    label = PACKED,
    filetypes = {"png"},
    open = true,
    load = false,
    onchange = function()
        local png_path = dlg.data[PACKED];
        infered_json_filename = app.fs.joinPath(app.fs.filePath(png_path), app.fs.fileTitle(png_path) .. ".json")
        -- weirdly still not effecting the file json default
        print(infered_json_filename)
    end
}:file{
    id = AJSON,
    label = AJSON,
    filename = infered_json_filename,
    filetypes = {"json"},
    open = true,
    load = false,
    onchange = function() print("test") end
}:show()

So I popup two file picker dialogs and after picking the png file, I want to auto-fill in the filepath for the next file picker dialog in infered_json_filename for ergonomic reasons. When I print it out it is correct but in the UI it is not updating, as you can see it still says “Select File”:

aseprite_tmp

1 Like

There is no two-way binding between a Lua variable and a dialog widget that uses it’s value, you need to call dialog:modify() to change the value:

    onchange = function()
        local png_path = dlg.data[PACKED];
        infered_json_filename = app.fs.joinPath(app.fs.filePath(png_path), app.fs.fileTitle(png_path) .. ".json")

        -- Now you need to modify the file widget for selecting a JSON file with the suggested file path
        dlg:modify{
            id=AJSON,
            filename = infered_json_filename
        }
3 Likes

Perfect! I couldn’t find dlg:modify in the docs strangely enough, or maybe I skipped over it, thanks!

1 Like