PDA

View Full Version : Self-referencing in float script controller


Paljas
07-12-2009, 11:37 AM
Hi,

I've googled my ass off, thought this was easy to find:

When writing a float script controller for some property of an object, how can you reference the object itself? I know you can use $instance_name if you know the name, but I want to write the controller script once, and copy the object multiple times, and don't want all to reference only the source object.

In my case, I have a light, and assigned a script controller to its intensity value. Somewhere in the script I need to get the position of the light the controller is for.

Gravey
07-12-2009, 01:20 PM
add the light as a node variable and use variableName.pos

Paljas
07-12-2009, 01:52 PM
add the light as a node variable and use variableName.pos
But then, when I copy the light, will the variable reference the source or the destination of the copy?

NM: I noticed I was lazy to ask and not just try ;). The variables references the new object, exactly what I want, thanks man!

Polimeno
07-12-2009, 09:35 PM
hey, take a deep look into MXS helpīs Interface: IScriptCtrl

simple test:



-- create the light
theLight = omniLight name:"light_omni" multiplier:200 rgb:(color 255 255 0) pos:[0,0,20]

-- add the CA
CA = attributes CustomCA
(
parameters mainP
(
script type:#float animatable:true
)
)
custAttributes.add theLight CA

-- create the float script
FS = float_script()
FS.addNode "theLight" theLight
FS.SetExpression "theLight.multiplier = 200"

--add the float script to the light CA
theLight.baseObject.CustomCA.script.controller = FS


notice the variable will auto-update when you copy the light multiple times.

hope it helps.

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