[Maxscript] A “not-modal” rollout declared inside a struct cannot access owner’s private members



Hi guys… I have a maxscript issue but believe me… I really don’t know what’s happening here!!!
While refactoring my scripts I’m trying different ways to do stuff and I’m applying (hoping in the proper way) some hints taken “here and there” about rollouts and structs.
My problem is that a rollout opened with modal:true works properly… but if opened with modal:false (or without it) fails to access a private member of the owner struct :tired_face:
And the “fun fact” is that it fails only inside events like the on button pressed or on dropdownlist selected!
If you try to access the private member for example inside the on MainUI open block it’s ok…
I wrote an example script… its structure is exactly the same of mine, only simpler.
The button and the dropdown list both read the content of the private array _List and the events simply print the value.

Here the working snippet…

global myStruct
	struct myStruct
			_self = myStruct,
			_List = #("AAA","BBB","CCC","DDD","EEE"),
			fn CreateNew = _self(),
			mainUI =
				rollout mainUI "Rollout" width:300 height:200
					local owner = if owner != undefined do owner
					button 'btn_1' "Btn" width:100 height:30 align:#center
					dropdownList 'ddl_List' "Account" align:#center
					label 'lbl_item' "--ITEM--" align:#center
					on mainUI open do
						ddl_List.items = owner._List
					on btn_1 pressed do
						print owner._List[ddl_List.selection]
						lbl_item.text = owner._List[ddl_List.selection]
					on ddl_List selected selectedItem do
						print owner._List[ddl_List.selection]
						lbl_item.text = owner._List[ddl_List.selection]
			fn ShowUI mode=
				createdialog mainUI modal:mode
			on create do
				mainUI.owner = this
	myStruct = myStruct()
myStruct.ShowUI true

If you change the last line with

myStruct.ShowUI false

You’ll receive a
– MAXScript Rollout Handler Exception:
– Runtime error: Attempting to access private member: “_List” in: (myStruct mainUI:Rollout:mainUI)

I discovered this problem while trying to add a second rollout (declared in the same way) and created pressing a button in the first one: I’ve set the first rollout as modal:false and set true the second… so had the error.

Any help will be very very appreciated!!!


I wouldn’t think you should be able to access the private properties from anything other than the structure. The rollout and the struct are two separate scopes.

I would suggest adding a getter and setter method for each private attribute. This tends to be a standard approach to private attribute encapsulation.

struct testStruct (
    Private _privateAttribute,
    Public Fn get_PrivateAttribute =(
        this._privateAttribute --return
    Fn set_PrivateAttribute inValue =(
        this._privateAttribute = inValue
  • Formatting on my phone is a bit rubbish but you get the idea.

You can also then validate that inValue is the type of data you want to assign to the privateAttribute


Yes this probably is the cleanest and proper way to do. I was tricked by the rollout: I was sure that because it were inside the struct it could access private stuff but things seem to be different.
Moreover there are too many strange behaviours with mod/not modal and open/pressed event.
Get and set or even “making members public” could be fine!