[Closed] max 2009 new Node Event System
hi,
I’ve a question about the new Node Event System in max 2009.
when i do this:
Fn ObjFn =
(
BoxeModeFn()
RenderableFn()
ViewTrajFn()
)
NewNodeSel = NodeEventCallback mouseUp:true delay:100 selectionChanged:ObjFn
i’ve got this answer:
>> MAXScript NodeEventCallback Exception: -- Argument count error: ObjFn wanted 0, got 2 <<
How could i fix this.
I’m using the ObjFn function to update my gui
thanks in advance guys
The error you get says, that the ObjFn funktion gets two variables while it expects none. But in the code you provided, it seems that you’re calling the function without giving it variables, so it shouldn’t throw that error. Are you sure, that’s the part causing problems, or are you calling the funktion elsewhere?
You have to use a function with two parameters as event handler for the NodeEventCallback system. These parameters give informations about the event.
Fn ObjFn ev nd =
(
BoxeModeFn()
RenderableFn()
ViewTrajFn()
)
NewNodeSel = NodeEventCallback mouseUp:true delay:100 selectionChanged:ObjFn
See the code samples in the documentation.
Ah…now I get it. The NodeEventCallback automatically gives these two parameters (Event and Node) to any function it calls. Therefore, the called function needs to accept those two parameters even if it doesn’t use them, else it fails and gives that error message.
Exactly. The Error Message sounds a bit counter-intuitive, but it is correct.
It tells you that the function ObjFn expects no arguments but got two. The callback always passes two arguments so it triggers and error regarding what the function expects, not what was passed. MAXScript cannot know why the function got two arguments passed because the Error Message is not generated by the callback calling the function but by the function itself being called, regardless what by.
After a while, you will learn to read it backwards and figure out what the real problem is.
The Reference clearly says
The callback functions take two parameters: the first is the event name that triggered the function call, the second is a list of node AnimHandles. The GetAnimByHandle() method must be used to get the node itself.
I will make sure that paragraph is more prominent in the next update.
Haven’t noticed this system before… the thing I’m wondering though, how to disable it when your done with it…!? Callbacks.removeScripts doesn’t see to do the trick…
Thanks,
-Johan
You set the variable that you stuck the event in to undefined and call gc light:true (or non-light if you’re so-inclined)
Yeah, I know, weird.
-- callbacky
fn objAdded a b = ( print "WHEE" )
objAdded()
-- the nodeEventCallback. Gotta store it in a variable
thisIsWeirdMan = nodeEventCallback added:objAdded
NodeEventCallback
-- let's create a sphere
sphere()
$Sphere:Sphere08 @ [0.000000,0.000000,0.000000]
"WHEE"
-- yay.
-- let's see what happens if we garbage collect
gc light:true
4907204L
sphere()
$Sphere:Sphere09 @ [0.000000,0.000000,0.000000]
"WHEE"
-- nodeEventCallback remains in variable 'thisIsWeirdMan'
-- let's kill that variable
thisIsWeirdMan = undefined
undefined
-- still working, though, aren't ya?
sphere()
$Sphere:Sphere10 @ [0.000000,0.000000,0.000000]
"WHEE"
-- of course you are. Hooray for garbage collection.
-- go away, demon undead variable!
gc light:true
4907124L
-- how about now?
sphere()
$Sphere:Sphere11 @ [0.000000,0.000000,0.000000]
-- hooray!
Richard thanks!
I got as far as setting it to undefined, but calling gc light was not even in my scope… but in a way it makes sense, could be a useful addition to the documentation as well.
-Johan
We’ll just have to wait for the next release then
On a related note: NodeEventCallback doesn’t show up in the indexlist.
Thanks!
-Johan
Noted!
“Node Event System” does, but “nodeEventCallback” does not.
Will be fixed…same time, same place.