hi I am newbie in moho scripting. and I cant find good resource for learning. I do some script before in other softs.
please help me to learn.
in this simple code i have 2 problem
1 . after press button moho message for create group you must first name it !
2 .line82 attempt to index field mohox (a nil value).
I want just return frame number.
and I want do this with call a function with press button..
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "bbb"
-- **************************************************
-- General information about this script
-- **************************************************
bbb = {}
function bbb:Name()
return self:Localize('UILabel')
end
function bbb:Version()
return '1.0'
end
function bbb:UILabel()
return self:Localize('UILabel')
end
function bbb:Creator()
return 'bbb'
end
function bbb:Description()
return self:Localize('Description')
end
function bbb:ColorizeIcon()
return true
end
-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************
function bbb:IsRelevant(moho)
return true
end
function bbb:IsEnabled(moho)
return true
end
-- **************************************************
-- bbbDialog
-- **************************************************
local bbbDialog = {}
bbbDialog.BUTTON_1 = MOHO.MSG_BASE
function bbbDialog:new()
local d = LM.GUI.SimpleDialog(bbb:Localize('UILabel'), bbbDialog)
local l = d:GetLayout()
d.button1Button = LM.GUI.Button(bbb:Localize('Button 1'), d.BUTTON_1)
l:AddChild(d.button1Button, LM.GUI.ALIGN_LEFT, 0)
return d
end
function bbbDialog:HandleMessage(msg)
if msg == self.BUTTON_1 then
bbb:nnnnn()
else
end
end
-- **************************************************
-- The guts of this script
-- **************************************************
function bbb:nnnnn(moho)
local mohox = moho
local dlog = bbbDialog:new(moho)
dlog:DoModeless()
frameN = self.mohox.frame
print(frameN)
end
function bbb:Run(moho)
local dlog = bbbDialog:new(moho)
dlog:DoModeless()
moho.document:SetDirty()
moho.document:PrepUndo(nil)
end
-- **************************************************
-- Localization
-- **************************************************
function bbb:Localize(text)
local phrase = {}
phrase['Description'] = ''
phrase['UILabel'] = 'bbb'
phrase['Button 1'] = 'Button 1'
local fileWord = MOHO.Localize("/Menus/File/File=File")
if fileWord == "Файл" then
phrase['Description'] = ''
phrase['UILabel'] = 'bbb'
phrase['Button 1'] = 'Button 1'
end
return phrase[text]
end
Last edited by davoodice2 on Wed Aug 18, 2021 6:59 pm, edited 1 time in total.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
synthsin75 wrote: ↑Wed Aug 18, 2021 7:02 pm
For #2, this is a bug that cropped up in 13.5.
On line 55, trying using: MOHO.MSG_BASE + 1
For #1, this is because bbbDialog:HandleMessage(msg) doesn't have access to "moho" to pass along to bbb:nnnnn(moho).
thanks master. is there any solution for 2?
I assume you mean for #1 (sorry, I answered them backwards).
This is a long standing problem for modeless dialogs. They don't have a readily available way to access "moho," which is why very little is done with modeless dialogs.
This is a long standing problem for modeless dialogs. They don't have a readily available way to access "moho," which is why very little is done with modeless dialogs.
All my dreams were dashed.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
function bbb:nnnnn(moho)
local mohox = moho
frameN = self.mohox.frame
print(frameN)
end
function bbb:Run(moho)
local dlog = bbbDialog:new(moho)
dlog:DoModal()
moho.document:SetDirty()
moho.document:PrepUndo(nil)
end
change modeles
but same error exist.
attempt to index field mohox (a nil value).
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "bbb_test"
-- **************************************************
-- General information about this script
-- **************************************************
bbb_test = {}
function bbb_test:Name()
return self:Localize('UILabel')
end
function bbb_test:Version()
return '1.0'
end
function bbb_test:UILabel()
return self:Localize('UILabel')
end
function bbb_test:Creator()
return 'bbb_test'
end
function bbb_test:Description()
return self:Localize('Description')
end
function bbb_test:ColorizeIcon()
return true
end
-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************
function bbb_test:IsRelevant(moho)
return true
end
function bbb_test:IsEnabled(moho)
return true
end
-- **************************************************
-- bbb_testDialog
-- **************************************************
local bbb_testDialog = {}
bbb_testDialog.BUTTON_1 = MOHO.MSG_BASE + 1
function bbb_testDialog:new(moho)
local d = LM.GUI.SimpleDialog(bbb_test:Localize('UILabel'), bbb_testDialog)
local l = d:GetLayout()
d.moho = moho
d.button1Button = LM.GUI.Button(bbb_test:Localize('Button 1'), d.BUTTON_1)
l:AddChild(d.button1Button, LM.GUI.ALIGN_LEFT, 0)
return d
end
function bbb_testDialog:HandleMessage(msg)
if msg == self.BUTTON_1 then
bbb_test:nnnnn(self.moho)
else
end
end
-- **************************************************
-- The guts of this script
-- **************************************************
function bbb_test:nnnnn(moho)
frameN = moho.frame
print(frameN)
end
function bbb_test:Run(moho)
local dlog = bbb_testDialog:new(moho)
dlog:DoModal()
moho.document:SetDirty()
moho.document:PrepUndo(nil)
end
-- **************************************************
-- Localization
-- **************************************************
function bbb_test:Localize(text)
local phrase = {}
phrase['Description'] = ''
phrase['UILabel'] = 'bbb_test'
phrase['Button 1'] = 'Button 1'
local fileWord = MOHO.Localize("/Menus/File/File=File")
if fileWord == "Файл" then
phrase['Description'] = ''
phrase['UILabel'] = 'bbb_test'
phrase['Button 1'] = 'Button 1'
end
return phrase[text]
end
But this self.moho will not update until the dialog is reopened.