Self referring script controller

Self referring script controller

Anonymous
Not applicable
745 Views
7 Replies
Message 1 of 8

Self referring script controller

Anonymous
Not applicable
I'm trying to make what seems like a pretty simple script controller. Lets say something simple like a script that scales the object based on the distance between it's parent node and the camera. The resulting script will be more complicated than that, but that's pretty much my first step.

I wanted to be able to instance this same script to a bunch of different objects so that they would all behave the same way, but independent of each other, so I don't want to directly specify the node I'm working with (other than the camera). And I definitely want to keep the script as an instance if possible.

What i'm looking for something along the lines of a "this.parent_node" operator, where "this" refers to the script controller itself and "parent_node" refers to the node it is attached to, which would vary depending on exactly which instance of the controller is being evaluated.

Is this possible, or am I heading down a dead end here?
0 Likes
746 Views
7 Replies
Replies (7)
Message 2 of 8

malikarn
Participant
Participant
Hi
have a look to mxs ref @

Maxscript language reference // 3ds max objects // animation controllers // Controller types // Script controllers // "this" local variable in scripted controllers.

indeed, you can't figure out wich instance of your script is attached to wich node. Maybe you can find a trick to make it by assigning unique ID to each instance...

++
0 Likes
Message 3 of 8

Anonymous
Not applicable
It's along the right lines for sure.. The example they posted even does kinda what I'm looking for, but only for unique script controllers. As an instanced script controller, however, each controller returns an array of all the nodes in the scene it is attached to. So there is no way to evaluate exactly which node a particular instance of the script controller is controlling.

I may be totally approaching this wrong. Perhaps instancing a script controller will always cause problems like this. Does a script controller exist as a completely independent node that is essentially the parent of the nodes it controls, or does it exist as something like the child of a regular node?

For instance.. If I said:

i = $box01.controller

I now have box01's controller as the variable 'i', but how do I resolve $box01 from 'i'? It seems like $box01 should be its parent of sorts, but it appears that it's much more complicated than that.
0 Likes
Message 4 of 8

Steve_Curley
Mentor
Mentor
Create a variable in the script controller, assign it to the node. If you only need access to a couple of of animatable values, use assign track instead, it's cheaper/quicker - nodes are quite "heavy".

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 8

Anonymous
Not applicable
Create a variable in the script controller, assign it to the node. If you only need access to a couple of of animatable values, use assign track instead, it's cheaper/quicker - nodes are quite "heavy".


Could you please elaborate on this. I'm not fully understanding what you are suggesting. I've explained why I can't assign a node variable directly. The script is being instanced over a number of different objects and each instance would need an independent variable.
0 Likes
Message 6 of 8

Steve_Curley
Mentor
Mentor
A simple example. Create a Box.
Command Panel | Motion Tab | expand Assign Controller | highlight z_Position | Assign a Float Script.
Create a variable mySelf, Assign Node and select $Box01
Change the actual script to read "mySelf.position.controller.x_position". Move the box along the X axis and it moves in Z by the same amount.
Shift+Move the box to clone it. Both boxes move independently - both have the script attached. You can prove that by looking at the properties of Box02 and highlighting the "mySelf" variable - the variable references "$Box02".

Note that the scripts are not instanced even if you clone the box to an instance. Changing the script on Box01 will not affect the script on Box02 (assuming Box02 already exists, with it's own script, before you change the script on Box01).

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 7 of 8

Anonymous
Not applicable
Note that the scripts are not instanced even if you clone the box to an instance. Changing the script on Box01 will not affect the script on Box02 (assuming Box02 already exists, with it's own script, before you change the script on Box01).


Thanks for your help, but this is precisely why it's not a solution to my problem. I need to the script to be instanced so that it can be edited from one central location. I also need to apply the script to objects that have already been created, so I'd have to 'Assign Node' for each object manually, of which there are hundreds.

I think I'll probably just write a script that actually generates the script controllers for me and applies them to each node. That way I can still edit the code from one place, but could still have a self-referring node variable that is different for each object.
0 Likes
Message 8 of 8

Steve_Curley
Mentor
Mentor

I think I'll probably just write a script that actually generates the script controllers for me and applies them to each node. That way I can still edit the code from one place, but could still have a self-referring node variable that is different for each object.

That would probably work. An alternative would be to use a dummy object and create a collection of the relevant nodes and simply loop through the list. Create the script on an animatable track which isn't used - like the Scale. Just remember to leave the default value as the last line of the script. I've not tried this (a collection inside a script controller) but it should work, and it means there really is only 1 copy of the script.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes