PDA

View Full Version : connect2way not going 2-way


bhnh
01-31-2008, 09:18 PM
Here's a code snippet wiring a 2-way connection between objects...


rollout wtest "Wire Test"
(
button btn_b1 "Make Box 1"
button btn_b2 "Make Box 2"
button btn_wire "Connect"

local b1, b2, amt

on btn_b1 pressed do
(
b1 = box()
)

on btn_b2 pressed do
(
b2 = box pos:[50,0,0]
)

on btn_wire pressed do
(
amt = -4
paramWire.connect2way b1.rotation.controller[#Z_Rotation]\
b2.rotation.controller[#Z_Rotation] "Z_Rotation" ("Z_Rotation*"+ amt as string)
)
)
createDialog 200 100
After executing this, if you rotate box1 then box2 behaves as advertised; it rotates four times for every one rotation of box1, in the opposite direction from box1. BUT if you rotate box2, multiplication by the variable is ignored, so both boxes rotate in the same direction at the same rate. When I wire this connection manually, the ratio of spin and direction is the same regardless of which box is rotated. What am I missing in the code to get the same results? Many thanks.

Caprier
01-31-2008, 09:28 PM
Maybe change

"Z_Rotation" ("Z_Rotation*"+ amt as string)
by

("Z_Rotation/"+amt as string) ("Z_Rotation*"+ amt as string)
?

Caprier
01-31-2008, 09:38 PM
I just tested it and it works:

rollout wtest "Wire Test"
(
button btn_b1 "Make Box 1"
button btn_b2 "Make Box 2"
button btn_wire "Connect"

local b1, b2, amt

on btn_b1 pressed do
(
b1 = box()
)

on btn_b2 pressed do
(
b2 = box pos:[50,0,0]
)

on btn_wire pressed do
(
amt = -4
paramWire.connect2way b1.rotation.controller[#Z_Rotation]\
b2.rotation.controller[#Z_Rotation] \
("Z_Rotation/"+amt as string) \
("Z_Rotation*"+ amt as string)
)
)
createDialog wtest 200 100

bhnh
01-31-2008, 10:02 PM
By golly, you're right. Another gold star for you, Pat :thumbsup:. Excuse my cranial density, but why does that work?

Caprier
01-31-2008, 10:20 PM
I'd say essentially because it was a lucky guess.

I think each object looks at the wiring formula, without regard for the other way.

If you try
"Z_Rotation * 3" "Z_Rotation * 5"
for example, it doesn't check if the relations are consistent, unlike what you enter in the Parameter Wiring dialog (some times). It seems to just apply the formula as it is.

bhnh
01-31-2008, 10:32 PM
OK... i think....

Caprier
01-31-2008, 10:43 PM
Now I don't know if this is intended or just one of these oddities.

As a see it, when you rotate one box, the other being wired will follow the formula. But then there should be a feedback to the first one, as it is also wired to the Z_Rotation parameter of the second.
Unless an explicit rotation overwrites the wiring.

So it could be made this way on purpose to allow more freedom to the animator, or just be bad programming practice.

We need someone who knows the inner mechanisms of max to clarify that point.

bhnh
01-31-2008, 11:38 PM
I agree. I notice that if I macro-record wiring a manual 2-way connection and then execute the macro, that the wiring will work as it's supposed to. But that double command is not present in the macro.

CGTalk Moderation
01-31-2008, 11:39 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.