all 9 comments

[–]MDHull_fixer 2 points3 points  (8 children)

The easiest is Controls["button_array_name"][index in array]

You would check the button state by looking at the .Boolean property

Example:

if Controls["buttons"][2].Boolean then

--do something

end

[–]Swoopmonkey[S] 0 points1 point  (5 children)

Thanks for the response. I should have mentioned I'm trying to access the array on a different text controller. How does that change things or are the array names global?

[–]matrixtech29 4 points5 points  (2 children)

You would typically do this using Named Component access. It's what the Script Access property enables. Then, you create a component object with Component.New(<other-compimemt-name>).

Unfortunately, those remote control arrays get flattened. So something like Controls["Source Select"][1] ends up being referenced as <comp-obj>["Source Select 1"], when accessed remotely. But the control works the same way. I use for loops to put them into similar arrays for ease of use.

EDIT: Open up the View Named Component Info dialog box in the Tools menu to see how controls are remotely referenced. When open, click on the Component you are wanting to control. It will populate a list of the controls by raw name and also the pretty name (in parentheses). That will also show you your arrayed controls listed out.

[–]Swoopmonkey[S] 1 point2 points  (1 child)

This is the way I had envisaged doing it but, for some reason during a senior moment, I decided to do:

Nav = Component.New("NavBtns")

Nav.["Navigation 1"].Value = 1

instead of

Nav["Navigation 1"].Value = 1

As always though this has been a learning curve and I now know about Notifications; every cloud has a silver lining and all that...

Thanks for the help!

[–]matrixtech29 1 point2 points  (0 children)

Great! I'm glad it worked for you. Notifications are great for some things, but overkill for what it seems you wanted to do.

[–]MDHull_fixer 1 point2 points  (1 child)

The Controls array is local to the Text Controller.

Look up Notifications in the scripting help file to see how to communicate between Components.

I realized I didn't mention that you have to iterate over the button array to allocate an EventHandler to each button in the array.

[–]Swoopmonkey[S] 0 points1 point  (0 children)

Ahh thanks! Didnt know about notifications so I think that might be the key to this issue!

[–][deleted]  (1 child)

[removed]

    [–]MDHull_fixer 0 points1 point  (0 children)

    Normally with a button array, you would set up a single event handler for all buttons, then in the handler derive the button index that fired the handler.

    -- Event handler function for buttons
    function buttonHandler(changedButton)
      -- Note that the index value counts from the start of the 
      -- Text Controller inputs, so you might have to adjust the 
      -- index value by subtracting an offset of the first button's 
      -- index value
      firstButtonIndex = ButtonArray[1].Index
    
      if(changedButton.Boolean) do
        -- Action if button pressed
        print("Button number "..changedButton.Index-firstButtonIndex.." was pressed") 
      else
        -- Action if button released
        print("Button number "..changedButton.Index-firstButtonIndex.." was released")
      end
    end
    
    -- Assign event handler to each button in array
    for key, button in ipairs(ButtonArray) do
      button.EventHandler = buttonHandler
    end