Trying to update my script to work in max 2019.
It was working fine in Max2016 where I added an event within a struct to a button within a group defined in the struct…but 2019 now has this documention:
“NOTE:You can only add functions that are registered in the global scope as event handlers. If you need to register a function that is hidden from the global scop (for example, contained in a struct), you need to define a global function to point to the hidden function.”
which is new in 2018
so I create a member function in a struct,
the struct is part of a rollout
it creates a button which attaches an event handler which executes the member function…
this is what I am kind of doing.
MasterValue = rollout ThisRollout "" width:200 ( local MyForm struct MyStruct = ( PUBLIC sName, function dunny = (print "nothing"), function CreateGui ( MyButton = dotnetObject "button" MyForm.controls.add MyButton global gdunny = this.dunny -- added this line to try and make events in the struct global dotnet.addEventHander MyButton "click" gdunny ), on create do ( CreateGui() ) ) function CreateWinform = ( MyForm = dotNetObject "MaxCustomControls.MaxForm" MyForm.showmodeless() ) button Maxbutton "" holderforstruct = #() on Maxbutton pressed do ( MyForm = CreateWinform() holderforstruct = MyStruct sName:"YANstruct" ) )
The code doesn’t actually work, the only additional lines I have put in to is the line “global gdunny = this.dunny” to essentially make a global variable and assign it to a function. I can execute the function from the listener, but the dotnet button refuses to do much at all.