ScriptSpot

Forum topic · General Scripting

Iterate through ui elements with "index"

By AlexH3D · 2013-03-23

Description

So basically I have several of the same ui elements kinda like this:


checkbutton ckb1
checkbutton ckb2
--...
checkbutton ckb32

I want to be able to set properties in-mass. So essentially:


fn massPropertySet =(
    i=1
    while i<=32 do(
        ckbi.state=false
        i+=1
    )
)

I also want to be able to have a single function that stores data into an array based on button suffix #, but I need to check the state of the button:


on ckb1 changed state do
    (storeData(1))

on ckb2 changed state do
    (storeData(2))

fn storeData num = (

     if ckbnum.state then(
          data[num] += <bitArray>
     else
          data[num] -= <bitArray>
)

--can work around with:
on ckb1 changed state do
    (storeData(1 ckb1.state))

on ckb2 changed state do
    (storeData(2 ckb2.state))

fn storeData num state= (

     if state then(
          data[num] += <bitArray>
     else
          data[num] -= <bitArray>
)

I tried storing the checkbuttons in an array but get and unknown system exception...


ckbArray=#(ckb1, ckb2)

So basically I need to be able to store the checkbuttons in an array, which doesn't look possible, or convert a string into a "checkbutton ui name" so I can refer to any checkbutton at will via index.

The latter is possible with scene objects, with the

<string> as name

function. Is there a way to do so with ui elements?

Comments (1)

Yes is possible.After you

barigazy · 2013-03-23

Yes is possible.
After you define checkburrons you can store it in array.

--u can use mapped function with on/off statement
mapped fn checkState cArr state:off = (cArr.checked = state)
button btn "CheckUncheck"
checkbutton cb1 "FirstCB"
checkbutton cb2 "SecondCB"
ctrlsArr = #(cb1,cb2)
on btn pressed do
(
if cb1.checked then checkState ctrlsArr else checkState ctrlsArr state:on

)