Struct initialize inside a variable

When I launch the script the first time I have this error: "Unknown property: "p_cbox" in undefined". But when I launch again the script I have no problem.
Can someone help me to initialize correctly p_cbox ?

struct MyStructure
(
	p_cbox = true,
 
	function fn_PropertiesUi =
	(
		try(destroydialog rol_Properties)catch()
 
		rollout rol_Properties " Properties"
		(
			checkbox cbox "try me" width:200 checked:p_cbox
 
			on cbox changed state do
			(
				cbox.checked = state
				ui.p_cbox = cbox.checked
 
				print ui.p_cbox
			)
		)
		rol_Properties
	),
 
	function fn_MainUi =  
	(
		rollout rol_Main ""
		(
			button btn "test"
 
			on btn pressed do
			(
				print ui.p_cbox
			)	
		)
		rol_Main
	),
 
	function fn_Run =
	(
		mainRollout = fn_MainUi()
		Createdialog mainRollout
 
		propertiesRollout = fn_PropertiesUi()
		Createdialog propertiesRollout
	)
)
 
ui = MyStructure()
ui.fn_Run()

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Rodman's picture

Thank you again !

It works perfectly now ! Very nice and impressive level !

Ps: Do you have your own website ? It would be great for us to know you more. I would follow your work. ;)

Rodman

barigazy's picture

...

:)

Thanks man.
I prepare my website but recently I'm very busy with my current job (architecture and industrial design not mxs). MXS is just a hobby.Also U can find me on CGTalk forum
(member name "gazybara").
Cheers!
Branko

bga

Rodman's picture

Let me know when you release

Let me know when you release your website. I found you already on CGTalk forum. I'm not on it but Google brought me here sometimes and your name appeared more than once. Autodesk can be thankful to have you sharing your knowledge to it community. You bring some lights to the darkest part of Maxscript.

Keep up the good work Branko ! And thanks again !

Rodman

barigazy's picture

...

U need to declare your struct as global variable

struct MyStructure
(
	p_cbox = true, propertiesRollout, mainRollout,
	fn fn_PropertiesUi =
	(
		try(destroydialog rol_Properties)catch()
		rollout rol_Properties " Properties"
		(
			checkbox cbox "try me" width:200 checked:p_cbox
			on cbox changed state do (cbox.checked = ui.p_cbox = state)
		)
		rol_Properties
	),
	fn fn_MainUi =  
	(
		rollout rol_Main ""
		(
			button btn "test"
			on btn pressed do (print ui.p_cbox)	
		)
		rol_Main
	),
	on create do 
	(
		mainRollout = fn_MainUi()
		Createdialog mainRollout
 
		propertiesRollout = fn_PropertiesUi()
		Createdialog propertiesRollout
	)
)
global ui = MyStructure()

bga

Rodman's picture

Thanks Barigazy for your help ! :)

But I still have the problem after a restart of 3ds Max ! :(

Also, I want to avoid as much as possible to declare a variable as Gloabal. In this case is it totally safe to use it ?

Rodman

barigazy's picture

...

Using the global in this case is best solution because this variable hold struct ei. all struct members (fn's, variables, rollouts etc.)

global ui = undefined
struct MyStructure
(
	p_cbox = on, propertiesRollout, mainRollout,
	fn closeDialog rollname = (if (hwnd = windows.getChildHWND 0 rollname parent:#max) != undefined do windows.sendMessage hwnd[1] 0x0010 0 0),
	fn fn_PropertiesUi =
	(
		propertiesRollout = rollout rol_Properties "PropsRoll"
		(
			checkbox cbox "try me" width:200 checked:ui.p_cbox
			on cbox changed state do (cbox.checked = ui.p_cbox = state ; print ui.p_cbox)
		)
	),
	fn fn_MainUi =  
	(
		mainRollout = rollout rol_Main "MainRoll"
		(
			button btn "test"
			on btn pressed do (print ui.p_cbox)	
		)
	),
	on create do 
	(
		ui = this
		closeDialog "PropsRoll" ; Createdialog (fn_PropertiesUi())
		closeDialog "MainRoll" ; Createdialog (fn_MainUi())
	)
)
ui = MyStructure()

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.