How to get the object index in a Container?

Discuss Lemur and share techniques.
Perun
Newbie
Posts:16
Joined:29 Feb 2016 10:13
How to get the object index in a Container?

Post by Perun » 22 Mar 2016 00:56

Hi,
Let's say I have 10 buttons (set to "switch" behavior) in a container. How can I get the object index of the currently selected button (x==1) inside the Container? In my scenario one button is selected at a time.
Thanks

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: How to get the object index in a Container?

Post by Softcore » 22 Mar 2016 11:49

Are you using ONE switch object with many rows - columns or are you using multiple switch objects?

Perun
Newbie
Posts:16
Joined:29 Feb 2016 10:13

Re: How to get the object index in a Container?

Post by Perun » 22 Mar 2016 16:14

I use ONE switch object with multiple rows/columns. All switches are packed into a container. The switches name hierarchy is:
Btn_0; Btn_1; Btn_2 etc.

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: How to get the object index in a Container?

Post by Softcore » 22 Mar 2016 16:30

Sorry still dont understand one thing....
Bu your description you have a lot of switches ( names you gave).

Do you want a way to find the "on" switch in each ONE object of multi-rows/columns? Then:

Code: Select all

Script on execution x

decl index = firstof(x);
The index declared above will give you the position of the active switch inside the x vector (array)

Or do you want to search for the on switch of all the objects combined?

Perun
Newbie
Posts:16
Joined:29 Feb 2016 10:13

Re: How to get the object index in a Container?

Post by Perun » 22 Mar 2016 18:31

Here is an simple image of my scenario shown below. I have several buttons in a Container (in this example 4 in one row) but in my actual setup there are about 80 buttons placed in rows and columns. One of them can be switched ON at a time. I have a simple script which switches OFF the last selected button automatically (that script is embedded into each button and executed "On Expression" x of the button.

I need to get the current selected button Index number in the Container. I.e the Container is the array and the example below.
I need something like that:
Index=Btn_Container[2] so the Index=2 in this example.
Attachments
btn_index.jpg
btn_index.jpg (48.07KiB)Viewed 5467 times

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: How to get the object index in a Container?

Post by Softcore » 24 Mar 2016 10:53

Ok got ya now....So you are using miltiple customSwitch objects.

Create an array (vector) inside your Container that inlcudes all your buttons' x.

so

array = {Btn_0.x, Btn_1.x,........Btn_80.x}

then use a script inside your container

On expression, buttons

decl Index = firstof(buttons);

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: How to get the object index in a Container?

Post by Softcore » 24 Mar 2016 10:55

Here's an example with 4 buttons
Attachments
example.jzml
(5.94KiB)Downloaded 196 times

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: How to get the object index in a Container?

Post by Softcore » 24 Mar 2016 11:00

But I dont get one thing...since you ALREADY have one script in EACH of the 80 buttons why dont you simply create a "index" expression and change that individually in EACH of the buttons - its just one added line of code.
Attachments
example2.jzml
(5.72KiB)Downloaded 206 times

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: How to get the object index in a Container?

Post by Softcore » 24 Mar 2016 12:21

By the way....if I were you I would definitely use ONE Switch object in Radio mode......and multiple rows - columns with labels...NOT a lot of CoustomSwitch objects. See how easy that is:
example3.jzml
(2.94KiB)Downloaded 294 times

Perun
Newbie
Posts:16
Joined:29 Feb 2016 10:13

Re: How to get the object index in a Container?

Post by Perun » 25 Mar 2016 17:53

THANKS A LOT!

I tried the examples and I could get the ideas. Example #1 is most closed to my project.
Great community - hugs!

Post Reply