moho:UpdateUI()
Moderators: Víctor Paredes, Belgarath, slowtiger
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
moho:UpdateUI()
anyone knows why moho:UpdateUI() cause crash in dialog?
- synthsin75
- Posts: 10253
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: moho:UpdateUI()
If memory serves, I think it's because it sets up an infinite loop with the dialog's update widgets function.
It's been quite a while since I've run into though.
It's been quite a while since I've run into though.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: moho:UpdateUI()
NO, just a simple example that shows the problem:
Code: Select all
-- **************************************************
-- General information about this script
-- **************************************************
ScriptName = "TestScript"
TestScript = {}
function TestScript:Name()
return 'Name'
end
function TestScript:Version()
return 'Version'
end
function TestScript:UILabel()
return 'UILabel'
end
function TestScript:Creator()
return 'Creator'
end
function TestScript:Description()
return 'Description'
end
-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************
function TestScript:IsRelevant(moho)
return true
end
function TestScript:IsEnabled(moho)
return true
end
-- **************************************************
-- Variables
-- **************************************************
local dialog_table = {}
-- **************************************************
-- Events
-- **************************************************
function TestScript:OnMouseDown(moho, mouseEvent)
end
function TestScript:DoLayout(moho, layout)
dialog_table.moho = moho
local dialog = LM.GUI.SimpleDialog('Dialog', dialog_table)
local dialog_layout = dialog:GetLayout()
local button = LM.GUI.Button('Update', MOHO.MSG_BASE)
dialog_layout:AddChild(button, LM.GUI.ALIGN_FILL, 0)
local popup = LM.GUI.PopupDialog('Popup', true, 0)
popup:SetDialog(dialog)
layout:AddChild(popup, LM.GUI.ALIGN_LEFT, 0)
end
function dialog_table:HandleMessage(msg)
--self.moho:UpdateUI() -- cause crash
end
- synthsin75
- Posts: 10253
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: moho:UpdateUI()
You can't call functions with self.moho outside of dolayout, as that only refers to the state of moho when the dialog is launched (there's no longer an actual object to be updated).
You need to use the script helper for dialog functions that don't take moho as an argument: https://mohoscripting.com/classes/ScriptInterfaceHelper
Try this instead:
You need to use the script helper for dialog functions that don't take moho as an argument: https://mohoscripting.com/classes/ScriptInterfaceHelper
Try this instead:
Code: Select all
function dialog_table:HandleMessage(msg)
local helper = MOHO.ScriptInterfaceHelper:new_local()
local moho = helper:MohoObject()
moho:UpdateUI() -- cause crash
helper:delete()
end
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: moho:UpdateUI()
brilliant! Thank You so much!