ScriptSpot

Forum topic · General Scripting

a registerTimeCallback problem

By mBlast · 2009-08-28

Description

Hi,

I'm new to maxscript - but not to max. I wanted to create a rollout which would give some information about an object's animation : distance between next and previous frame, distance from the origin of the movement, etc...
I thought that it wouldn't be to hard to script... i was wrong ! the whole script works, except that i can't display the information in the rollout : i only can print it to the listener - which is not what i want. Here is a simple script that resume the problem :

---------- SCRIPT TEST -----------

if ((test_roll != undefined) and (test_roll.isdisplayed)) do (destroyDialog test_roll)
unRegisterTimeCallback refreshObjData
global objetSelect
global interfP1
fn objetFilter objetSelect = (superClassOf objetSelect == geometryClass)
fn refreshObjData =
(
frameP1 = currentTime +1
At time currentTime objPosX = objetSelect.pos.x
At time frameP1 objPosXP1 = objetSelect.pos.x
ecartSuivMm = (objPosXP1 - objPosX)
print ecartSuivMm
)

----------------
-- Rollout --
----------------

rollout test_roll "testUI"
(
label interfP1 "Intervalle f+1 : " align:#left pos:[10, 10]
pickbutton pbt_selObj "Select. objet" autoDisplay: true pos:[10, 40] width:80 filter:objetFilter

on pbt_selObj picked objetSelect do
(
if objetSelect != undefined do
(
select objetSelect
registerTimeCallback refreshObjData
)
)
)

createDialog test_roll 150 80

---------------

The whole thing is, i guess, about the refreshObjData function : how could i replace the "print ecartSuivMm" by something that would display the "ecartSuivMm" value in the rollout after the label "Intervalle f+1 :". I've search the maxscript help and found nothing. I'm sure the solution is quite simple but i have no idea left ! Please help me !!!

Comments (4)

Anubis · 2009-08-29

Ok, at the very beginning and I missed to meet variables scope but it is fundamental and necessary in all scripts. There is a topic in maxScript Reference and I recommend it to you. Here is a hint in your question, all variables declared on root level is a global, for example if you type in Listener A=5, that means you already declared A as a global variable. Here's why I moved inside the rollout your filter function, to make it local. Briefly your rollout test_roll in this case is a global variable, so all what you need is to call it's controllers value, ie if you enter in Listener:
test_roll.showme.text will return label showme string value. And to assign new value just use:

test_roll.showme.text = "String Value Here"

. For more clear try the example from the screenshot.
Rollout Access

mBlast · 2009-08-29

Your explanation is just fantastic - i now understand better the way global/local variables are working, and also how to reach a rollout property. With your exemple it just took me minutes to make my script works. Many thanks for your help, Anubis

Anubis · 2009-08-28

There is an short example (without callbacks, also without globals):

if (test_roll != undefined) do
	if (test_roll.isdisplayed) do
		(destroyDialog test_roll)

rollout test_roll "testUI"
(
	fn objSelFilter obj = (superClassOf obj == geometryClass)
	label showme "" align:#left pos:[10, 10]
	pickbutton pbt_selObj "Select. objet" autoDisplay:true pos:[10, 40] width:80 filter:objSelFilter
	
	on pbt_selObj picked obj do
	(
		if obj != undefined do
		(
			result = (At time (currentTime+1) obj.pos.x) - (At time currentTime obj.pos.x)
			showme.text = result as string
		)
	)
)

createDialog test_roll 150 80

mBlast · 2009-08-28

Hi Anubis, many many thanks for your answer - your way to code is much more efficient than mine ! But i'm afraid i didn't explain my problem well enough : the thing is that i would like the info to be refreshed automatically in the rollout when i move the slidertime - that's why i'm using the registerTimeCallback function.
The maxscript help says that this function is executed in a separate stack, so the local variables can't be passed to it. That's why i use global variable. But i don't know how to make the label that writes the value ("showme" in your example) a global variable too, i think it could be a solution. I hope this is clear enough this time - sorry. And again thanks for helping