PDA

View Full Version : How to select and object by a name plus a variable


CerberusC
04-12-2009, 03:52 PM
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.

SyncViewS
04-12-2009, 04:28 PM
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
select (execute(sPrefix + (i as String)))

ForceCompleteRedraw()
)
)

on btSelect pressed do
(
setSel()
)
)

createDialog rolTest 90 30 style:#(#style_toolwindow, #style_border, #style_sysmenu)
)

- Enrico

Bobo
04-12-2009, 04:48 PM
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

CerberusC
04-12-2009, 07:29 PM
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!

SyncViewS
04-12-2009, 08:09 PM
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

CGTalk Moderation
04-12-2009, 08:09 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.