Notifications
Clear all

[Closed] Loop Issue?

Hello,
I’m confused about my setup here. I’m trying to place and then wire an array of dummies (path constrained to a spline) to the first dummy in the array. Can anyone tell me why my script isn’t working? Thanks for helping out a maxscript noob!

myArray = selection as array–selection of dummies path constrained to line01

for i in 2 to myArray.count do
(
paramWire.connect $myArray [1].pos.controller.Path_Constraint.controller[#Percent]
$myArray [i].pos.controller.Path_Constraint.controller[#Percent]
“Percent-(.1*i)”
)

12 Replies

$myArray[i] should be myArray[i].
$ is only used when denoting a node path, like $Box01. myArray already contains a node pointer and you don’t need (and cannot use) $ to access it.

so I tried that and nothing happened so then tried removing the same symbol from $myArray[1] and got the error message:
incompatible types: 0.1, and undefined.

but then the dummies were all moved to 0.1 percent along the spline (but without any wiring to myarray[1] evident)

True, that’s because “i” is not defined in the context of the Wire Controller’s expression. So “0.1*i” means “0.1 * undefined”. You have to use

(“Percent-(0.1*”+ i as string + “)”)

as expression to insert the value of i into it.

So the correct code (which I tested this time myself) is

myArray = selection as array--selection of dummies path constrained to line01

for i in 2 to myArray.count do
(
paramWire.connect myArray[1].pos.controller[#Percent] myArray[i].pos.controller[#Percent] ("Percent-(.1*"+i as string +")")
)

thanks for going so far as to test the script too B. I’ve been trying to troubleshoot this possibly unrelated issue where this message pops up which prevents the script from executing:

– Error occurred in i loop
– Frame:
– i: 2
– Runtime error: connect requires subAnims

Hopefully i can get it up and running after reading through the maxscript document.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Did you try the code I posted? Your code had the wrong controller/subanim struct and caused that same error when I tried it. My code actually did what you expected – I got the dummies running on the spline path and changing the leading dummy moved the rest.

also, I get this variation on that error message when it’s run out of the maxscript editor window:

– Error occurred in i loop; filename: C:\Documents and Settings\Administrator\Desktop; position: 177
– Frame:
– i: 2
– Runtime error: connect requires subAnims

really scratching my head on this one since I’m copying and pasting your code. Other things I do before running the script:
I create a line, create a dummy, path constrain the dummy to the line, shift drag it to create copies, select all copies, hitting ‘execute all’ in mxs editor. getting the feeling it must be a real noob issue i’m overlooking

I reproduced EXACTLY the same steps here and it works as expected.
There must be something strange going on over there.

After executing the script, can you enter this:

myArray[1].pos.controller[#Percent]

and tell me what it returns?

so my computer and my coworker’s computer get a message saying ‘undefined’. must be doing something wrong over here. can’t believe a 3 line for loop is putting me to shame

I’m not in front of Max but doesn’t the loop have to be either:

for i in myArray do

or

for i = 2 to myArray.count do

myArray = selection as array--selection of dummies path constrained to line01

for i = 2 to myArray.count do
(
paramWire.connect myArray[1].pos.controller[#Percent] myArray[i].pos.controller[#Percent] ("Percent-(.1*"+i as string +")")
)

for i = 2 to myArray.count do

I believe the ‘=’ sign and ‘in’ both stand for the same thing in this case. Also tried your other suggestion but also was a no go. I should be able to resolve this tonight and will post again afterwards. thanks!

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

There is no bug in the code, there is something about your SCENE that is different.
Start scanning your object’s controller structure in the Listener to see what the real deal is.

For example, select the one Dummy and say

$.pos.controller
 -->Controller:Path_Constraint
 $.pos.controller[#percent]
 -->SubAnim:Percent

There is a chance that the controller structure of your object is different, for example if I take a Dummy that has no Path Constraint, I get

$.pos.controller
 -->Controller:Position_XYZ
 $.pos.controller[#percent]
 -->undefined
 

So stop looking for a syntax error in your code and start looking for a logical error in your setup – something about your Dummies could different and it might depend on how the controllers were assigned/copied etc. You might have List Controllers embedded to hold both a Percentage and something else, or something different that is extraordinary.

Page 1 / 2