help to solve problem

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

help to solve problem

Post by davoodice2 »

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..

and what is 'moho' into prentices.

Code: Select all

-- **************************************************
-- 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.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 9984
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: help to solve problem

Post by synthsin75 »

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).
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: help to solve problem

Post by davoodice2 »

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?
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 9984
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: help to solve problem

Post by synthsin75 »

davoodice2 wrote: Wed Aug 18, 2021 7:04 pm
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.
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: help to solve problem

Post by davoodice2 »

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. :? :?
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: help to solve problem

Post by davoodice2 »

I changed this part

Code: Select all

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).
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 9984
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: help to solve problem

Post by synthsin75 »

Since a dialog's HandleMessage doesn't have access to "moho", you need to define d.moho in the dialog's new().

Code: Select all

-- **************************************************
-- 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.
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: help to solve problem

Post by davoodice2 »

But this self.moho will not update until the dialog is reopened.
thank you so much.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
Post Reply