struct + RCmenu Bug


#1

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


#2

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 :slight_smile:

-Johan


#3

confirmed in max 2009. weird…


#4

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()

#5

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


#6

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


#7

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)


#8

@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 :slight_smile:

-Johan


#9

That is just wacky. All I have to say.


#10

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


#11

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


#12

That is part of the reason that I have stuck with doing it that way. Also just so I have every thing setup the same way. If you need it you just initialize is and a way you go. Plus I have never had issues with doing it this way. I guess I have just stuck with what is working.


#13

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.