show/hide multiple items


I am trying to have four items be shown or hidden, showing and hiding 2 items works fine but when i try to show/hide the same 2 items and add 2 new items things do not function properly

("glasses" is in the sacript as when the code was done it was designed for various accesories, now it is mainly just footwear)

please see script example below-thanks for any help

 

 function show_hide_glasses(){

  if(count==1){ 

          var item_glass1 = Scene.findNodeByLabel( "blue shoe L" );

var item_glass1_2 = Scene.findNodeByLabel( "blue shoe" );

        if (glass_count == 1)

        { item_glass1.setVisible( true );

  item_glass1_2.setVisible( true );

}  else   {     

          item_glass1.setVisible( false );

  item_glass1_2.setVisible( false );

}

          var item_glass1 = Scene.findNodeByLabel( "blue shoe L" );

var item_glass1_2 = Scene.findNodeByLabel( "blue shoe" );

var item_glass1 = Scene.findNodeByLabel( "spikes L" );

var item_glass1_2 = Scene.findNodeByLabel( "spikes" );

        if (glass_count == 2)

        { item_glass2.setVisible( true );

  item_glass2_2.setVisible( true );

}  else   {     

          item_glass2.setVisible( false );

  item_glass2_2.setVisible( false );

}

 

 

Comments

  • DafaDafa Posts: 97
    edited April 2021

    Just an FYI, you can select multiple nodes in the scene, and go to the Properties tab and select "All" and then search for Visibility and disable it. That way, you can select all the nodes you want to be hidden without having to go through each individual node and hiding it.

     

    But if you insist, the issue you are running into is that item_glass2 and item_glass2_2 have not been declared.

    Did you mean to change 

    // ...var item_glass1 = Scene.findNodeByLabel("spikes L");var item_glass1_2 = Scene.findNodeByLabel("spikes");// to this?var item_glass2 = Scene.findNodeByLabel("spikes L");var item_glass2_2 = Scene.findNodeByLabel("spikes");

    I'm confused by your code, but if the above works, woohoo!

    Post edited by Dafa on
  • Richard HaseltineRichard Haseltine Posts: 100,988

    You have a lot of variables that seem to spring from nowhere, and aren't given initial values - count and glass_count. It almost looks as if you are expecting the separate variables to behave as an array, which they won't if they are not created as an array.

  • VicSVicS Posts: 1,273

    yeah someone wrote the code for me, i didnt put glass2 becasue the next line has the number 2, here is another line further down if this helps clarify

     

     function show_hide_glasses(){

    if(count==1){

    var item_glass1 = Scene.findNodeByLabel( "3 front short L" );

    var item_glass1_2 = Scene.findNodeByLabel( "3 front short" );

    if (glass_count == 1)

    { item_glass1.setVisible( true );

    item_glass1_2.setVisible( true );

    } else {

    item_glass1.setVisible( false );

    item_glass1_2.setVisible( false );

    }

     

     

    var item_glass1 = Scene.findNodeByLabel( "3 front short L" );

    var item_glass1_2 = Scene.findNodeByLabel( "3 front short" );

    var item_glass1 = Scene.findNodeByLabel( "3 2 spikes L" );

    var item_glass1_2 = Scene.findNodeByLabel( "3 2 spikes" );

    if (glass_count == 2)

    { item_glass2.setVisible( true );

    item_glass2_2.setVisible( true );

    } else {

    item_glass2.setVisible( false );

    item_glass2_2.setVisible( false );

    }

     

     

    var item_glass3 = Scene.findNodeByLabel( "3 front closed toe L" );

    var item_glass3_2 = Scene.findNodeByLabel( "3 front closed toe" );

    if (glass_count == 3)

    { item_glass3.setVisible( true );

    item_glass3_2.setVisible( true );

    } else {

    item_glass3.setVisible( false );

    item_glass3_2.setVisible( false );

    }

  • VicSVicS Posts: 1,273

    wait sorry that code was messed up, im gonna try to get it more precise then i will repost it, I see I enetyered a wrong number, ill be back in a while later.....

  • VicSVicS Posts: 1,273

     I changed the 1 to a 2 , i think this is what Dafa suggested, what happen is when the second option is clicked -the one with blue shoe and spikes is that the spikes turn on but the blue shoe is getting hidden, so still only two items are getting shown and not the desired 4 items,  i hope that clarifies it and makes more sense--here it is....

     

    function show_hide_glasses(){

      if(count==1){ 

              var item_glass1 = Scene.findNodeByLabel( "blue shoe L" );

    var item_glass1_2 = Scene.findNodeByLabel( "blue shoe" );

            if (glass_count == 1)

            { item_glass1.setVisible( true );

      item_glass1_2.setVisible( true );

    }  else   {     

              item_glass1.setVisible( false );

      item_glass1_2.setVisible( false );

    }

              var item_glass2 = Scene.findNodeByLabel( "blue shoe L" );

    var item_glass2_2 = Scene.findNodeByLabel( "blue shoe" );

    var item_glass2 = Scene.findNodeByLabel( "3 2 spikes L" );

    var item_glass2_2 = Scene.findNodeByLabel( "3 2 spikes" );

            if (glass_count == 2)

            { item_glass2.setVisible( true );

      item_glass2_2.setVisible( true );

    }  else   {     

              item_glass2.setVisible( false );

      item_glass2_2.setVisible( false );

    }

  • VicSVicS Posts: 1,273

    spmeone wrote me...."you added two new items to hide/show, however all you did in the code was change the values of your existing variables instead of adding New variables for these nodes/objects."

     

    someone , who i havent been able to get a hold of lately wrote this....i know so little abotu coding that im not sure what he meant when he said..."change the values of your existing variables instead of adding New variables for these nodes/objects."

  • VicSVicS Posts: 1,273

    i did get it to work---however when i click the first option nothing happens now-

    second option all four items appear-second option hides all 4 items but doesnt show the 2 items it is supposed to-please see code below if anyone can help me with this-thanks

     

    Dafa-not sure what you meant by this or does that apply to hiding items from a dialoque box?

    "Just an FYI, you can select multiple nodes in the scene, and go to the Properties tab and select "All" and then search for Visibility and disable it. That way, you can select all the nodes you want to be hidden without having to go through each individual node and hiding it."

     

             var item_glass1 = Scene.findNodeByLabel( "3 front short L" );

    var item_glass1_2 = Scene.findNodeByLabel( "3 front short" );

    if (glass_count == 1)

    { item_glass1.setVisible( true );

    item_glass1_2.setVisible( true );

    } else {

    item_glass1.setVisible( false );

    item_glass1_2.setVisible( false );

    }

     

     

    var item_glass2 = Scene.findNodeByLabel( "3 front short L" );

    var item_glass2_2 = Scene.findNodeByLabel( "3 front short" );

    var item_glass2_3 = Scene.findNodeByLabel( "3 2 spikes L" );

    var item_glass2_4 = Scene.findNodeByLabel( "3 2 spikes" );

    if (glass_count == 2)

    { item_glass2.setVisible( true );

    item_glass2_2.setVisible( true );

    item_glass2_3.setVisible( true );

    item_glass2_4.setVisible( true );

    } else {

    item_glass2.setVisible( false );

    item_glass2_2.setVisible( false );

    item_glass2_3.setVisible( false );

    item_glass2_4.setVisible( false );

  • Richard HaseltineRichard Haseltine Posts: 100,988

    What is the value of glass_count? You can always add print statements to try to track what is happening (they will appear under the script box if you execute in the ScriptIDE pane, or in the log file if you run from a script)) e.g.

    var item_glass1_2 = Scene.findNodeByLabel( "3 front short" );print( glass_count );if (glass_count == 1){ print( "In the set visible section" );item_glass1.setVisible( true );item_glass1_2.setVisible( true );

     

Sign In or Register to comment.