Page 1 of 1

is SimpleDialog() crashing my code? - string "lolua: embedded Lua code"]:4: bad argument #1 to 'for iterator' (table exp

Posted: Thu May 01, 2025 7:30 pm
by JoshuaOkonkwo
Hello, there is a common problem I'm noticing with writing scripts in Moho.
It seems like this line SimpleDialog() causes this problem:

Code: Select all

[string "lolua: embedded Lua code"]:4: bad argument #1 to 'for iterator' (table expected, got nil)
I think this because when I run this debug check, everything runs smoothly until I try to create the dialog instance.

Code: Select all

    LM.GUI.Alert(LM.GUI.ALERT_WARNING, "this alert shows before error", nil, nil, "OK")

    local dialog = LM.GUI.SimpleDialog() 

    LM.GUI.Alert(LM.GUI.ALERT_WARNING, "this does not show at all", nil, nil, "OK")
I don't know if this has something to do with my computer, or my code, but I've not just noticed this with my code, I've seen it with another.

What can I do?

This part of the software is supposed to create and display a dialog box where the user can enter some values.

I have searched online, on this forum, restarted MOHO several times, tried the script on different documents.
Nothing works.

Re: is SimpleDialog() crashing my code? - string "lolua: embedded Lua code"]:4: bad argument #1 to 'for iterator' (table

Posted: Thu May 01, 2025 9:25 pm
by Stan
LM.GUI.SimpleDialog expects two arguments. See here: https://mohoscripting.com/methods/lm.gui-simpledialog.

If you try the Create New Script tool on mohoscripting.com, it will generate you a working example:

Code: Select all

local MyScriptDialog = {}

function MyScriptDialog:new()
    local d = LM.GUI.SimpleDialog('', MyScriptDialog)
    local l = d:GetLayout()
    return d
end

function MyScript:Run(moho)
    local dlog = MyScriptDialog:new(moho)
    if (dlog:DoModal() == LM.GUI.MSG_CANCEL) then
        return
    end
    -- ...
    
end