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

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
JoshuaOkonkwo
Posts: 10
Joined: Sun Feb 16, 2025 10:36 am
Contact:

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

Post 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.
Hunreal Moves - Available for work.
https://www.behance.net/hunrealmoves
Donations: https://paypal.me/JoIyke
Stan
Posts: 217
Joined: Sun Apr 19, 2009 3:22 pm

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

Post 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
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
Post Reply