PDA

View Full Version : Node Event Callback Question


CerberusC
03-08-2009, 10:19 PM
I want to make a callback that calls a function when the material of an object is changed.

I know that whit the node event callback i can do this, but i don't understand well how to use it, how to register a callback and how to unregister.

The function i must use is the "materialOtherEvent:" but i don't know how to use it.

Plase some help

Cheers!

CerberusC
03-08-2009, 10:25 PM
I think i understand how it is working thanks to this post...
http://forums.cgsociety.org/showthread.php?f=98&t=725434&highlight=NodeEventCallback

But i still do not understand well...the node event callback is stored inside a variable?

So i can have a variable in my script, let the variable be undefined, when i want to activate it i store the callback inside the variable and when i want to deactivate it a change the variable to undefined and do a gc light.

Is this ok?

Cheers.

ZeBoxx2
03-08-2009, 10:35 PM
yep

make sure your variable 'lives' as long as you need it... which in most cases means you'll have to make it a global.

CerberusC
03-08-2009, 10:39 PM
mmm not sure if it's working, i'll report in a while

CerberusC
03-08-2009, 10:43 PM
It's not working.

i'm using this function with a checkbox:



fn prico a b = (
print "i work"
)

on mats changed state do (
if state == on then (
callmat = NodeEventCallback materialOtherEvent:prico
print "soy callbo"
)
else (
callmat = undefined
gc light:true
print "me voy"
)
)



but the callback is not working :p

CerberusC
03-08-2009, 10:53 PM
ok, i don't understand anythig...

when i check and uncheck the checkbox many fast times and in the end i left the checkbox checked then the callback is working, if i check only the first time...it is not working... :S

P.S. : but every time i check and uncheck the phrase "soy callbooo" is printed, so the function that activates the callback is working

ZeBoxx2
03-08-2009, 11:21 PM
first... like I said.. make sure the variable you assign the node event callback 'lives' for as long as you need it... right now you're assigning it to a variable inside the checkbox's change state event handler, and then within an if-test at that. Outside of that if-test, the variable doesn't exist. Make it global before the script.

The other thing you may want to change is the event type; the help file is slightly misleading, you need the 'materialStructured' event to detect material assignments;


global callmat

fn prico a b = (
print "i work"
)

rollout roll_test "test" (
checkbox mats ""
on mats changed state do (
if state == on then (
callmat = NodeEventCallback materialStructured:prico
print "soy callbo"
)
else (
callmat = undefined
gc light:true
print "me voy"
)
)
)

createDialog roll_test


Edit: 'materialOtherEvent' is used to detect changes to the material itself.. e.g. changing the diffuse color of the material used by a node will signal this event.

CerberusC
03-08-2009, 11:30 PM
But i don't need to see the material assignement, i need to see the material changes, i mean when i change a color, when i change the opacity, etc...

And the variable, sorry i did not write it here, i have the variable defined as global at the top of my script. :p

So i don't understand why when i check and unchek 4 or five times fast the it's working :p

P.S. :SORRY I DID NOT READ THE LAST PART OF THE POST, TESTING IT

P.S. 2 : that's exactly what i need :)

CerberusC
03-08-2009, 11:47 PM
ZeBoxxx your script is doing the same thing, it is working inly if i check and uncheck the checkbox a few times, i don't understand why is doing that :p

ZeBoxx2
03-08-2009, 11:48 PM
err... lots of edits.. just to make sure: does it work for you now, with the 'materialOtherEvent' back in? It works here, at least.

As for toggling quickly... don't know, haven't tried; given that you're garbage collecting repeatedly, I'd say "don't do that" ;)
( not sure why the node event system was implemented the way it is )

ZeBoxx2
03-08-2009, 11:50 PM
welp, dunno... works here even if I toggle the checkbox like a madman...



global callmat

fn prico a b = (
print "i work"
)

rollout roll_test "test" (
checkbox mats ""
on mats changed state do (
if state == on then (
callmat = NodeEventCallback materialOtherEvent:prico
print "soy callbo"
)
else (
callmat = undefined
gc light:true
print "me voy"
)
)
)

createDialog roll_test

"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"me voy"
"soy callbo"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"
"i work"

CerberusC
03-08-2009, 11:52 PM
it is only working if i check and unckeck a few times...i don't understand why :p

I mean, if i launch the script and check the checkbox...it's not working...if i repeteadly checkand uncheck, then it works (with the checkbox checked of course), if i uncheck is nor working (it is ok) but if i check it again it is not working again...so i need to check and uncheck repeteadly :s

EDIT: i don't know if that can affect...but i'm going to restart my comp :s

CerberusC
03-09-2009, 12:13 AM
not working fine yet :p

CerberusC
03-09-2009, 12:35 AM
I make it work, but instead of activating or deactivating the callback, the callback is always working, but the function i call depends on a variable, if the variable is set to true then the function print the phrase, and if it's set to false then the function don't do anything.

Obviously the variable value is changed with the state of the checkbox.

It seems to work in this way, but i don't know why the other way is not working fine for me :s

Cheers! :D

CGTalk Moderation
03-09-2009, 12:35 AM
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.