Notifications
Clear all

[Closed] paramWire float_script problem

Hello, all. I could sure use a little guidance on the following (here’s a .swf synopsis – http://www.e-nimation.com/turbosquid/floatScriptIssue/floatScriptIssue.htm ).

Here’s a simple rollout that makes two boxes and point. The boxes each have a boolean custom attribute (“engage”), and a float_script is attached to the point.

(
ca = attributes predecessor
(
parameters main rollout:params
(
pred type:#Node
engage type:#boolean ui:btn_engage default:true
)
rollout params "Predecessor Test"
(
button btn_engage "Engage Button"
 
on btn_engage pressed do
(
engage = not engage
print engage
)
 
)
)
rollout predtest "FloatScript-ColorSwitch"
(
button btn_init "First Box"
button btn_next "Next Box"
local p, i=50, holder, fs
 
on btn_init pressed do
(
b = box()
custAttributes.add b ca
p = b
 
)
on btn_next pressed do
(
b = box pos:[i,0,0] 
custAttributes.add b ca
b.pred = p
holder = point()
holder.parent = b
fs = float_script()
holder.position.x_position.controller = fs
fs.addNode "cube" b
fs.script = "try (with animate off (if cube.engage
then cube.pred.wirecolor = blue else cube.pred.wirecolor = red 
 0))catch(0) "
i += 50
p = b
)
)
createDialog predtest 200 60
)

The color of the first box is dictated by the “engage” state of the second box. It works just fine, and works when animated, as well.

OK, here’s a second rollout that’s identical to the first one, except that the color switch has been replaced by a paramWire tying the z_rotations of the two boxes together…

(
ca = attributes predecessor
(
parameters main rollout:params
(
pred type:#Node
engage type:#boolean ui:btn_engage default:false
)
rollout params "Predecessor Test"
(
button btn_engage "Engage Button"
 
on btn_engage pressed do
(
this.engage = not this.engage
print engage
)
 
)
)
rollout predtest "FloatScript-ParamWire"
(
button btn_init "First Box"
button btn_next "Next Box"
local p, i=50, holder, fs
 
on btn_init pressed do
(
b = box()
custAttributes.add b ca
print b.engage
p = b
 
)
on btn_next pressed do
(
b = box pos:[i,0,0] 
custAttributes.add b ca
b.pred = p
b.engage = false
-- the next few lines are needed to make the wire animatable in Max9 and higher
paramWire.disconnect2way b.pred.rotation.controller.z_rotation.controller \
b.rotation.controller.z_rotation.controller 
b.engage = true
paramWire.connect2way b.rotation.controller[#z_rotation] \
b.pred.rotation.controller[#z_rotation] ("Z_rotation") ("Z_rotation")
holder = point()
holder.parent = b
fs = float_script()
holder.position.x_position.controller = fs
fs.addNode "cube" b 
fs.script = "try (with animate off (if cube.engage 
then 
(paramWire.connect2way cube.rotation.controller[#z_rotation] \
	cube.pred.rotation.controller[#z_rotation] (\"Z_rotation\") (\"Z_rotation\")) else 
paramWire.disconnect2way cube.pred.rotation.controller.z_rotation.controller \
cube.rotation.controller.z_rotation.controller
 0))catch(0)" 
i += 50
p = b
)
)
createDialog predtest 200 60
)

Now, the on/off feature for the paramWire works fine if you’re not animating, but in animation mode it doesn’t work. It malfunctions in both Max8 and Max9, so I’m assuming that the float_script is missing something. Any thoughts, please? Many, many thanks.

4 Replies

Tyson Ibele pointed out to me that the connection/disconnection of a wire parameter is not animatable, which got me out the internal feedback loop I was in and led to a solution.

Rather than trying to connect, disconnect and reconnect, I tried simply multiplying one of the param expressions by a variable. When the connection is “off” the variable is zero; when the connection is “on” the variable is some float value.

(
ca = attributes predecessor
(
parameters main rollout:params
(
pred type:#Node
engage type:#float ui:btn_engage default:2.0
disengage type:#float ui:btn_disengage default:0.0
)
rollout params "Predecessor Test"
(
button btn_engage "Engage"
button btn_disengage "Disengage"
 
on btn_engage pressed do
(
this.engage = 2.0
print engage
)
 
on btn_disengage pressed do
(
this.engage = 0.0
print engage
)
)
)
rollout predtest "FloatScript-ParamWire"
(
button btn_init "First Box"
button btn_next "Next Box"
local p, i=50, holder, fs 
 
on btn_init pressed do
(
b = box()
custAttributes.add b ca
print b.engage
p = b
 
)
 
on btn_next pressed do
(
b = box pos:[i,0,0] 
custAttributes.add b ca
b.pred = p
b.engage = 2.0
paramWire.disconnect2way b.pred.rotation.controller.z_rotation.controller \
b.rotation.controller.z_rotation.controller 
paramWire.connect2way b.rotation.controller[#z_rotation] \
b.pred.rotation.controller[#z_rotation] ("Z_rotation") ("Z_rotation*"+ b.engage as string)
holder = point()
holder.parent = b
fs = float_script()
holder.position.x_position.controller = fs
fs.addNode "cube" b 
fs.script = "paramWire.connect2way cube.rotation.controller[#z_rotation] \
cube.pred.rotation.controller[#z_rotation] (\"Z_rotation\") \
(\"Z_rotation*\"+cube.engage as string)
0"
i += 50
p = b
)
)
 
createDialog predtest 200 60
)

There’s a bit of a catch to this when animating. Let’s say you’ve got a 20-frame animation with box2 rotating. Box1 is linked at a ratio of 2:1 so both rotate. Now, at frame 10 you insert a keyframe changing the ratio to zero. What happens is that between frames 1 and 10 the ratio decrements from 2.0 to 0, so box1’s rotation slows til frame 10, when it stops altogether. To achieve the on/off effect another keyframe has to be inserted at frame 9, setting the ratio to 2.0. So from frame 1 to frame 10 the ratio’s 2.0, and starting a frame 11 it’s zero. QED.

Thanks, Tyson!:buttrock:

Also, another alternative would have to ramp up/down the weight value of the controller you wanted to turn on or off. Sorry for coming in when you already figured it out

Good heavens, don’t apologize, Jason. I’m not sure how to go about that method… isn’t .weight a property of float_lists only?

Yes it is. I quickly read the thread here, thought you were dealing with an object’s Z rotation track.