PDA

View Full Version : Loop Issue?


Pennink
06-13-2010, 02:17 PM
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)"
)

Bobo
06-13-2010, 04:03 PM
$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.

Pennink
06-13-2010, 05:35 PM
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)

Bobo
06-13-2010, 11:13 PM
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 +")")
)

Pennink
06-15-2010, 01:40 PM
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.

Bobo
06-15-2010, 01:52 PM
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.

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.

Pennink
06-15-2010, 03:13 PM
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

Bobo
06-15-2010, 09:29 PM
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.

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?

Pennink
06-16-2010, 02:15 PM
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

jonahhawk
06-17-2010, 06:24 AM
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 +")")
)

Pennink
06-17-2010, 01:37 PM
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!

Bobo
06-17-2010, 02:13 PM
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!

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.

Pennink
06-18-2010, 03:12 AM
Bobo, you were right and with the a little trouble shooting help from Nils Norgren over at neoscape, we found that assigning a path constraint to the dummy from the drop down menu (and not the motion panel) was also setting up a position list controller. So the code was actually referring to the first position controller which was not the path constraint percent value. Thanks so much for helping me with this little code--it's really motivating after having figured this out

CGTalk Moderation
06-18-2010, 03:12 AM
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.