PDA

View Full Version : Callback doubt calling a function


CerberusC
02-27-2009, 02:34 PM
Ok i have a problem, i have a function called pri() and i want to execute it back when i change the viewport, but i receive an error, here is my script:


rollout pri_v "callback test" width:450 height:400
(

checkbutton start "GO!" checked:false
button stop "NO GO!"


fn pri = (
print "c"
)

fn pro = (
print "b"
)

on start changed state do
(
if state == on then
(
pri()
callbacks.addScript #viewportChange "pri()" id:#pri_test
)
else
(
pro()
callbacks.removeScripts #viewportChange id:#pri_test
)

)

on stop pressed do (
pro()
callbacks.removeScripts #viewportChange id:#pri_test
)

)
spdfloater = newRolloutFloater "callback test" 460 90
addRollout pri_v spdfloater


and here is the output when i move the viewport:


-- Error occurred in anonymous codeblock; filename: none; position: 0
-- Frame:
-- pri: undefined
>> MAXScript Callback script Exception: -- Type error: Call needs function or class, got: undefined <<
-- called in anonymous codeblock
-- Frame:
-- pri: undefined
>> MAXScript Callback script Exception: -- Type error: Call needs function or class, got: undefined <<
"b"


Help me please, i don't understand why is happening that.

SyncViewS
02-27-2009, 02:50 PM
Hi Juan,
in order to make the callback work, you need to fully specify the function address inside the rollout.

Change:callbacks.addScript #viewportChange "pri()" id:#pri_test with: callbacks.addScript #viewportChange "pri_v.pri()" id:#pri_testIt will work.

- Enrico

CerberusC
02-27-2009, 02:52 PM
GREAT! it works.

Thanks :D

CerberusC
02-27-2009, 05:08 PM
Ok, now i have the previous script working, but when i select an object or i do something the callback execute the function 4 times and i get 4 "C" printed.

Can someone explain me why and how to limit that?
Cheers!

Mathieson
02-27-2009, 06:31 PM
I don't really have anything back up my theory because the callback doesn't return anything through the notificationParam call, but here is my theory anyways!

Sent everytime the viewport parameters change, including panning, zooming and orbiting the viewport or changing the active viewport.
It sounds like there are multiple triggers for this callback, and it might be that selecting an object triggers 4 of them at once.

CerberusC
02-27-2009, 10:33 PM
Thanks Mathieson.

is there a way to change this callback for another that only responds to pan, orbit and zoom the viewport? or at least that responds to middle mouse button?

Cheers! :D

CGTalk Moderation
02-27-2009, 10:33 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.