Saving tool button states when switching between tools?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Saving tool button states when switching between tools?

Post by lehtiniemi »

When I have for example a checkbox in my tool top bar, its value gets reset when I switch to another tool and back.

Is it possible to save this state so that the value stays the same even if I switch to other tools inbetween?
User avatar
hayasidist
Posts: 3511
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Saving tool button states when switching between tools?

Post by hayasidist »

yes.

load and save prefs

for example

Code: Select all

function HS_Test_harness:SavePrefs(prefs)

	prefs:SetBool("HS_Test_harness.trace", self.trace)
	prefs:SetBool("HS_Test_harness.diagnose", self.diagnose)
	prefs:SetFloat("HS_Test_harness.n1", self.n1)
	prefs:SetFloat("HS_Test_harness.n2", self.n2)
	prefs:SetString("HS_Test_harness.uut", self.uut)


end

function HS_Test_harness:LoadPrefs(prefs)

	self.trace = prefs:GetBool("HS_Test_harness.trace", true)
	self.diagnose = prefs:GetBool("HS_Test_harness.diagnose", true)
	self.n1 = prefs:GetFloat("HS_Test_harness.n1", 0)
	self.n2 = prefs:GetFloat("HS_Test_harness.n2", 0)
	self.uut = prefs:GetString("HS_Test_harness.uut", defaultOn)

end

function HS_Test_harness:ResetPrefs()

	self.trace = true
	self.diagnose = true
	self.n1 = 0
	self.n2 = 0
	self.uut =  defaultOn
	
end

Last edited by hayasidist on Mon Mar 21, 2016 12:37 pm, edited 1 time in total.
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: Saving tool button states when switching between tools?

Post by lehtiniemi »

hayasidist wrote:yes.

load and save prefs

for example

Code: Select all


function HS_Real_Time:SavePrefs(prefs)

	self.useIK = prefs:GetBool("HS_Real_Time.useIK", true)
	self.boneFBF = prefs:GetBool("HS_Real_Time.boneFBF", false)


end


function HS_Real_Time:LoadPrefs(prefs)

	prefs:SetBool("HS_Real_Time.useIK", self.useIK)
	prefs:SetBool("HS_Real_Time.boneFBF", self.boneFBF)

end


function HS_Real_Time:ResetPrefs()

	HS_Real_Time.useIK = true
	HS_Real_Time.boneFBF = false

end

Thanks. Again. :)
User avatar
hayasidist
Posts: 3511
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Saving tool button states when switching between tools?

Post by hayasidist »

error in original post -- updated -- please disregard the post to which you replied
Post Reply