@Pennink (Pennink) posted a new topic, subject "Loop Issue?". It read:

   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)”  
    )

Then @Bobo (Bobo) said

    $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 (Pennink) replied

    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 (Bobo) replied

    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
    [code] 
        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 +")")
        )
        
    [/code]

After which, @Pennink (Pennink) added

    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 (Bobo) replied

    Pennink:
    
    > 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.

To which @Pennink (Pennink) replied

    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

After which, @Bobo (Bobo) added

    Pennink:
    
    > 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:
    [code] 
        myArray[1].pos.controller[#Percent]
        
        
    [/code]
    
    and tell me what it returns?

After which, @Pennink (Pennink) added

    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

To which @jonahhawk (jonahhawk) replied

    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
    [code] 
        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 +")")
        )
        
    [/code]

To which @Pennink (Pennink) replied

    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 (Bobo) replied

    Pennink:
    
    > 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
    [code] 
        $.pos.controller
         -->Controller:Path_Constraint
         $.pos.controller[#percent]
         -->SubAnim:Percent
        
    [/code]
    
    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
    [code] 
        $.pos.controller
         -->Controller:Position_XYZ
         $.pos.controller[#percent]
         -->undefined
         
        
    [/code]
    
    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.

So @Pennink (Pennink) replied

    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

After which, @CGTalk_Moderation (CGTalk_Moderation) added

    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.


{'source': 'discourse', 'url': 'https://forums.cgsociety.org/t/loop-issue/1437646', 'title': 'Loop Issue?', 'views': 365, 'has_accepted_answer': False, 'word_count': 1061, 'like_count': 0, 'reply_count': 11, 'participant_count': 4, 'posts': 14, 'tags': '', 'author': '@Pennink (Pennink)', 'participants': '@Pennink (Pennink), @Bobo (Bobo), @jonahhawk (jonahhawk), @CGTalk_Moderation (CGTalk_Moderation)', 'image_url': '', 'created_at': '2010-06-13T07:17:47.000Z', 'last_posted_at': '2010-06-17T20:12:54.000Z'}