[Closed] Callback doubt calling a function
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.
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 "[B]pri_v.[/B]pri()" id:#pri_test
It will work.
- Enrico
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!
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.
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!