Fandom

Foldit Wiki

Foldit Lua Function dialog.Show

1,463pages on
this wiki
Add New Page
Comments0 Share

dialog.Show Edit

Function
integer dialog.Show(table dialogTable)
Description
Show dialog.
V1 Function Name
New to V2
More Information
Details

Remarks Edit

dialog.Show() takes a Lua table, created with the dialog.CreateDialog() function, as an argument. The dialog is then shown and the recipe waits until it is closed by clicking a button or the X in the upper right of the dialog. It returns the value of the button that is clicked, or 0 if the cancel X on the dialog is clicked.

After the dialog.Show() returns, you can retrieve the values of the individual controls using the .value property.

Example Edit

Below is an example of creating a dialog from Lua. The first dialog displays some controls and gathers information. If the OK button is clicked, a second dialog is constructed that shows the values that were selected.

The names of the controls are arbitrary, and can be any valid Lua variable name.

local ask = dialog.CreateDialog("Test Dialog")
ask.Instructions = dialog.AddLabel("Set these values:")
ask.Invert = dialog.AddCheckbox("Invert", true)
ask.Iterations = dialog.AddSlider("Iterations", 3, 1, 25, 0)
ask.BandStrength = dialog.AddSlider("Band Strength", 5.3, 0.1, 10.0, 1)
ask.Comment = dialog.AddTextbox("Comment", "Cool!")
ask.OK = dialog.AddButton("OK", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
if (dialog.Show(ask) > 0) then
    local tell = dialog.CreateDialog("Test Dialog Results")
    if (ask.Invert.value) then
        tell.Invert = dialog.AddLabel("Invert=true")
    else
        tell.Invert = dialog.AddLabel("Invert=false")
    end
    tell.Iterations = dialog.AddLabel("Iterations="..ask.Iterations.value)
    tell.BandStrength = dialog.AddLabel("Band Strength="..ask.BandStrength.value)
    tell.Comment = dialog.AddLabel("Comment="..ask.Comment.value)
    tell.OK = dialog.AddButton("OK", 1)
    dialog.Show(tell)
else
    print("Dialog cancelled")
end

This produces a dialog that looks like this: Dialog

The code below prints the values passed back from the dialog. Useful for determining what values were used when running a recipe.

local function _PrintDialogValues(t)
    print('---- '..t._Title..' ----')
    for i,v in ipairs(t._Order) do
        if t[v].controlType ~= 0 then
            print(v..'='..tostring(t[v].value))
        end
    end
    print('-------------------------------')
end

The code below prints the all the values used in the dialog. Possibly useful for debugging.

local function _PrintDialogTable(t)
    print('---- Dialog '..t._Title..' ----')
    for i,v in ipairs(t._Order) do
        local s = v..'=('
        local first=false
        for k,v2 in pairs(t[v]) do
            if not first then
                first = true
            else
                s = s..','
            end
            s = s..k..'='..tostring(v2)
        end
        s = s..')'
        print(s)
    end
    print('-------------------------------')
end

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.