Notifications
Clear all

[Closed] Self-referencing in float script controller

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.

3 Replies

add the light as a node variable and use variableName.pos

1 Reply
(@paljas)
Joined: 11 months ago

Posts: 0

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!

hey, take a deep look into MXS help´s [b][b]Interface: IScriptCtrl

[/b][/b]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.