Callback doubt calling a function

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2009   #1
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.
__________________
If there's no spoon you must eat the soup with your hands, don't let the tool be your life, be an artist.
 
Old 02 February 2009   #2
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_test
It will work.

- Enrico
__________________
IllusionCatalyst – Instrument set for 3ds Max │ AliquaForma – Personal portfolio in fieri
 
Old 02 February 2009   #3
GREAT! it works.

Thanks
__________________
If there's no spoon you must eat the soup with your hands, don't let the tool be your life, be an artist.
 
Old 02 February 2009   #4
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!
__________________
If there's no spoon you must eat the soup with your hands, don't let the tool be your life, be an artist.
 
Old 02 February 2009   #5
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!

Quote: 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.
 
Old 02 February 2009   #6
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!
__________________
If there's no spoon you must eat the soup with your hands, don't let the tool be your life, be an artist.
 
Old 02 February 2009   #7
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:18 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.