Struct not working need help.


#1

Hi,
I have some problem with my struct…
When you press on the button Set version I got this: Struct member access requires instance: setVersion

The setVersion() is in the btnChooseCamera event.

If I move it inside the rollout open event it is working… :frowning: But I need it in the btnChooseCamera…

I need help can’t figure out how to fix this.

	clearListener()
  	
  	struct mainStruct
  	(
  		public a,
  		
  		private
  		Version = "2012.1",
  		
  		public fn getVersion =
  		(
  			GetAppData TrackViewNodes 1000
  		),
  
  		public fn setVersion =
  		(
  			SetAppData TrackViewNodes 1000 cameraManVersion
  		),
  		
  		private fn displayUI =
  		(
  			rollout CameraRollout "Camera 2012" width:719 height:425
  			(
  				button btnChooseCamera "Set version" pos:[5,347] width:170 height:20
  			
  				on CameraRollout open do
  				(
  					format"Tool version: %
" getVersion()
  				)
  			
  				on btnChooseCamera pressed do
  				(
  					setVersion()
  				)
  			)
  			createDialog CameraRollout picked 
  		),
  		
  		private fn initStruct =
  		(
  			displayUI()
  		),
  		
  		private _init = initStruct()
  	)
  	
  	cameraInstance = mainStruct()
  	

#2

A rollout has no access to the struct it is inside. You will have to do it like this:

	clearListener()
  	global cameraInstance 
  	struct mainStruct
  	(
  		public a,
  		
  		private
  		Version = "2012.1",
  		
  		public fn getVersion =
  		(
  			GetAppData TrackViewNodes 1000
  		),
  
  		public fn setVersion =
  		(
  			SetAppData TrackViewNodes 1000 cameraManVersion
  		),
  		
  		private fn displayUI =
  		(
  			rollout CameraRollout "Camera 2012" width:719 height:425
  			(
  				button btnChooseCamera "Set version" pos:[5,347] width:170 height:20
  			
  				on CameraRollout open do
  				(
  					format"Tool version: %
" cameraInstance.getVersion()
  				)
  			
  				on btnChooseCamera pressed do
  				(
  					cameraInstance.setVersion()
  				)
  			)
  			createDialog CameraRollout picked 
  		),
  		
  		private fn initStruct =
  		(
  			displayUI()
  		),
  		
  		private _init = initStruct()
  	)
  	
  	cameraInstance = mainStruct()
  	

In general this is not an advised pattern design for maxscript.


#3

Ok thanks,
but what are a good pattern design :slight_smile: Always looking to improve my knowledge.
A better way of doing this would be the get out the UI of the Struct or it’s deeper then that?

Thanks,


#4

I can only speak for myself, most of my maxscript tools are either:

  • Global rollout only
    or
  • Global struct instance and global rollout, independent from each other (not one inside the other)

#5

actually you can get it to work without a global by using a local rollout variable and it’s open event

clearListener()
 
 struct mainStruct
 (
 	public a,
 	
 	private
 	Version = "2012.1",
 	
 	public fn getVersion =
 	(
 		GetAppData TrackViewNodes 1000
 	),
 
 	public fn setVersion =
 	(
 		SetAppData TrackViewNodes 1000 cameraManVersion
 	),
 	
 	private fn displayUI =
 	(
 		rollout CameraRollout "Camera 2012" width:719 height:425
 		(
 			[b]local parent[/b]
 			
 			button btnChooseCamera "Set version" pos:[5,347] width:170 height:20
 		
 			on CameraRollout open do
 			(
 				[b]parent = this[/b]
 			)
 		
 			on btnChooseCamera pressed do
 			(
 				[b]parent.[/b]setVersion()
 			)
 		)
 		createDialog CameraRollout picked 
 	),
 	
 	private fn initStruct =
 	(
 		displayUI()
 	),
 	
 	private _init = initStruct()
 )
 
 cameraInstance = mainStruct()

#6

Have you tested this? not working for me


#7

yep… i can’t work in this implementation. but the idea is right.
this assignment has to be moved out of rollout…


#8

tested and working on max 2010


#9

yes! it works! i was wrong. it works for 2010 and 2012. of course after fixing:


  --SetAppData TrackViewNodes 1000 cameraManVersion
  SetAppData TrackViewNodes 1000 Version
  

i do exactly the same but i set rollout’s local properties before the rollout openning.
in this case:


  ...
  	 private fn displayUI =
  	 (
  		 rollout CameraRollout "Camera 2012" width:719 height:425
  		 (
  			 local parent = if parent != undefined do parent
  			 
  			 button btnChooseCamera "Set version" pos:[5,347] width:170 height:20
  		 
  			 on btnChooseCamera pressed do
  			 (
  				 parent.setVersion()
  			 )
  		 )
  		 CameraRollout.parent = this
  		 createDialog CameraRollout picked 
  	 ),
  ...
  

it helps me set also some locals used in rollout UI creation…


#10

Excuse my ignorance but what does this line do:

local parent = if parent != undefined do parent

I’ve seen it before but I don’t understand it’s purpose.

Thanks.


#11

it protects the local variable from overwriting on create dialog action. without this trick the variable will be set to undefined (or other predefined value):


try(destroydialog presetRol) catch()
rollout presetRol "" width:200
(
--	local buttonWidth
	local buttonWidth = if buttonWidth == undefined then 95 else buttonWidth 
		
	button bt "The Button" width:buttonWidth align:#center
)
presetRol.buttonWidth = 190
createdialog presetRol


#12

Right I get it now. I’ll have play on Monday when I’m back in work.

Thanks for the explanation.


#13

This solution is Great . Build a rollout in a Structure!. :thumbsup:


#14

This solution is Great . Build a rollout in a Structure!. :thumbsup:

Buuuut . I try this exmple: and i think the rollout in a struct has a “STATIC” property.Means ONLY one copy in the structure …



struct Person 
(
	str,
	age,
	rol,
	
	fn BuildRol = (
		rollout rol ""
		(
			local parent = if parent != undefined do parent
			button b "Press Me" 
			
			on b pressed do (
				print (" I am " + parent.str + ". and I am " + parent.age as string + " years old.")
			)
		)
		rol.parent = this
	),
	fn init = (
		BuildRol()
	),
	tmp = init()
)

boo = Person str:"Hello" age: 23
coo = Person str:"Tommm" age: 48

createdialog boo.rol 
-- press the Button result : " I am Tommm. and I am 48 years old."

createdialog coo.rol 
-- press the Button result : " I am Tommm. and I am 48 years old."

--- The Same Result ---


Is that right ???


#15

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.