Notifications
Clear all

[Closed] How to select and object by a name plus a variable

I mean:

I have a bunch of objects:

box1
box2
box3

and i have a variable

namev = 0

now i have a timer:

timer timo “timo” interval:2000 active:true

and now i have an order that executes everytime the timer ticks:

on timo ticks do (
namev = namev + 1

 if namev == 3 do ( --here i reset the variable to 0
     namev = 0
 )

)

now i want that every time the variable changes the object that contains that variable in it’s name became selected.

in other words:

how can i select teapot1 by an order like : “select $teapot/namev”

or something like that, i don’t know if i’m explaining myself in a good way.

Cheers.

4 Replies

Hi Juan,
if I understood well, you want to select each object in a set with the same prefix and a variable number. The following script shows how to accomplish it by composing the object name with “execute”.

(
    rollout rolTest "Select it"
    (
        button btSelect "Showtime!" width:80 align:#center
    
        function setSel =
        (
            sPrefix = "$Teapot0"
        
            Teapot pos:[-50, 50, 0]
            Teapot pos:[0, 0, 0]
            Teapot pos:[50, -50, 0]

            ForceCompleteRedraw()

            for i = 1 to 3 do
            (
                sleep 1
                [B]select (execute(sPrefix + (i as String)))[/B]
                
                ForceCompleteRedraw()
            )
        )
    
        on btSelect pressed do
        (
            setSel()
        )
    )
    
    createDialog rolTest 90 30 style:#(#style_toolwindow, #style_border, #style_sysmenu)
)

  • Enrico

Use getNodeByName() to get your node, or undefined if it does not exist.

So you could say

theNode = getNodeByName (“box” + namev as string)
if isValidNode theNode do select theNode

Thanks to you two.

The bobo’s solution was the more factible this time, but your is usefull too for other thing Enrico.

I have another problem now, i’ll post in the forum.

Cheers!

Hey Juan,
I’m glad to help, this is not a competition, I learnt something new too. “getNodeByName” is a cleaner a solution, and I’m definitely not a fan of the “execute”.

  • Enrico