Notifications
Clear all

[Closed] struct + RCmenu Bug

 JHN

Can anyone confirm this is a bug:


struct jhn 
(
	_menu = rcmenu _menu
	(
		subMenu "File"
		(
			menuItem mi_close "Close" --checked:false
		)
	),
	
	_ui = rollout _ui ""
	(
		button ng "o"
	)
)		

JHN = jhn()

The above gives an error


struct jhn 
(
	_ui = rollout _ui ""
	(
		button ng "o"
	),
	
	_menu = rcmenu _menu
	(
		subMenu "File"
		(
			menuItem mi_close "Close" --checked:false
		)
	)
)		

JHN = jhn()

The next script works…!? Looks like rcmenu’s doen’t play nice with structs…

-Johan

11 Replies
 JHN

It gets weirder


struct jhn 
(
	_menu = rcmenu _menu
	(
		subMenu "File"
		(
			menuItem mi_close "Close" --checked:false
		)
	)
	,
	_ui = rollout _ui ""
	(
		button ng "o"
	)
)		

JHN = jhn()

It’s the same code as the first example only the comma is placed on a newline…and now it works!? I’m helped with that, but as a syntactical junkie, I’m not amused

-Johan

confirmed in max 2009. weird…

 PEN

Something that I have always done is put everything in a functions. So just wrap the RC menu in a function and call the function. I do this for the rollouts as well and then store the result of the rollout back in a local variable in the struct.

I should mention that the run function is like a toggle for the UI now.

struct jhn 
 (
 	uiRollout=undefined,
 	fn menu_Fn=
 	(
 		rcmenu _menu
 		(
 			subMenu "File"
 			(
 				menuItem mi_close "Close" --checked:false
 			)
 		)
 	),
 	
 	fn rollout_fn=
 	(
 		rollout _ui ""
 		(
 			button ng "o"
 		)
 	),
 	
 	fn run=
 	(
 		
 		if uiRollout!=undefined then
 		(
 			destroyDialog uiRollout
 			uiRollout=undefined
 		)else
 		(
 			uiRollout=rollout_fn()
 			createDialog uiRollout menu:(menu_Fn())
 		)
 	)
 )		
 
 JHN = jhn()
 JHN.run()
 JHN

Hi Paul,
I feel I shouldn’t wrap my menu’s in function, that way it’s also a bit hard to get access to them. When placed in a struct I can still write values to local variables in the menu, because I can easily access them through the struct object modell. If I spawn them from a function I can’t do that easily… It’s also presonal preference to “wrap” as less as possible.

Gravey, I used 2009 as well, should have mentioned that. Thanks for confirming though!

-Johan

1 Reply
(@ofer_z)
Joined: 11 months ago

Posts: 0

Hi Johan,

You can use wrapper functions and still access the rollout/rcmenu just as you would if you assigned them directly. Just assign the resulting rcmenu/rollout to a local struct variable (like Paul did for the rollout in his example), so to exapnd on Paul’s code, you’d add a struct variable _menu, and in the run function add _menu = menu_Fn. This will create the menu and assign it to the _menu variable, and from that point on, you can access it just as you would in you code.

BTW, you can automatically initialize the rollout and rcmenu when the struct is instanciated as I explain here.

hOpe this helps,
o

 PEN

Just so you know it wasn’t working in 2008 either. Have you ever had this work?

Seems like you must have a newline after the closing parenthesis of an rcmenu inside a struct (you can’t follow it with a comma on the same line)

This doesn’t give a syntax error:

struct jhn 
   (
   	_menu = rcmenu _menu
   	(
   		subMenu "File"
   		(
   			menuItem mi_close "Close" --checked:false
   		)
   	)
  	,
   	
   	_ui = rollout _ui ""
   	(
   		button ng "o"
   	)
   )		
   
   JHN = jhn()

But this does:

struct jhn 
  (
  	_ui = rollout _ui ""
  	(
  		button ng "o"
  	),
  	
  	_menu = rcmenu _menu
  	(
  		subMenu "File"
  		(
  			menuItem mi_close "Close" --checked:false
  		)
  	),
  	foo = "foo"
  )		
  
  JHN = jhn()
  

(checked in Max9 & Max2009)

 JHN

@Paul
No, this is the first time I’m building a tool with this struct/dialog/rcmenu declaration, so I sort of stumbled upon this. I’m sticking with the newline + comma markup, adding a comment behind it not to alter it.

@Mike
Yes I figured that too, so i’m sticking with the syntactical wrong notation to get it right

-Johan

 PEN

That is just wacky. All I have to say.

 JHN

Hi Ofer,

Yes I already do the init “trick” with my script, but for the sake of this bug I totally stripped my script. Indeed I see you can catch a menu when you assign the return of a function to a variable If you return the menu, thanks for that, but it still makes me wonder why you would want that, I don’t see the advantage over just declaring it in the struct directly (apart from the whacky bug). Only thing I can think of is when you have lots of menu’s and don’t need all of them at the same time, then you could just init a menu that you would like. Am I right in thinking so?

Thanks,
-Johan

Page 1 / 2