PDA

View Full Version : max 2009 new Node Event System


holycause
02-01-2009, 07:36 PM
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 ;)

Piflik
02-01-2009, 07:55 PM
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?

ypuech
02-01-2009, 09:57 PM
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.

Piflik
02-01-2009, 10:08 PM
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.

Bobo
02-02-2009, 02:26 AM
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.

holycause
02-02-2009, 11:34 AM
Exactly. The Error Message sounds a bit counter-intuitive, but it is correct.

OK.

I didn't know it was possible to do it like this.

Thanks a lot guys. ;)

JHN
02-04-2009, 12:40 PM
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

ZeBoxx2
02-04-2009, 12:48 PM
the thing I'm wondering though, how to disable it when your done with it...!?
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!

JHN
02-04-2009, 01:21 PM
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

Bobo
02-04-2009, 02:39 PM
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

It is added already. Just not in 2009 ;)

JHN
02-04-2009, 03:07 PM
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

Bobo
02-04-2009, 04:39 PM
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.

CGTalk Moderation
02-04-2009, 04:39 PM
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.