Getting Multiple Buttons In Script

Discussion in 'Technical Discussion' started by Larry Pendleton, Jan 20, 2019.

  1. Larry Pendleton

    Larry Pendleton Boxer

    Joined:
    Aug 2, 2018
    Messages:
    58
    Likes Received:
    10
    I have a Jump node, and I am trying to find both buttons in the same Jump node script?

    Code:
    let jumpLeftButton = self.ui().find('Jump Left')[0]; //jump left button
    let jumpRightButton = self.ui().find('Jump Right')[1]; //jump right button
      
    log(jumpLeftButton);
    log(jumpRightButton); 
    my logs are showing:
    [object Button]
    undefined

    Thanks
    -Larry
     
  2. Larry Pendleton

    Larry Pendleton Boxer

    Joined:
    Aug 2, 2018
    Messages:
    58
    Likes Received:
    10
    DOH!
    Code:
    let jumpLeftButton = self.ui().find('Jump Left')[0]; //jump left button
    let jumpRightButton = self.ui().find('Jump Right')[0]; //jump right button
     
    log(jumpLeftButton);
    log(jumpRightButton); 
    Now my logs are showing:
    [object Button]
    [object Button]

    Good grief, lol. I just had to think a little about what was happening. "find" will search your UI, and find (as an array) the element that is named 'Jump Left' and return in the first array index [0], and so always use index [0] when searching for other buttons in your UI, because it's doing the same thing.

    Lesson learned!

    -Larry
     

Share This Page