ScriptSpot

Forum topic · General Scripting

Selecting with variable name

By kuroiei · 2012-01-17

Description

Hello, coders!

Today, I'm struggling to improve my script a little. I want the user to fill some editText boxes, in order to point the script to the proper object to be selected. Before that I had simple


if $prefix_body_suffix == undefined
	then
(
)

but it was way to rigid, it forced the user to rename objects that they would fit into the way my script used them. So then I created some editText boxes, made some global variables and tried to work them in, but with no effect.


if $(syntax_prefix + "body" + syntax_suffix) == undefined
	then
(
)

The main thing is - I don't know and can't find a way to select ($) objects that have names composed out of string variables. Can anybody help?

Thanks in advance and cheers!

Comments (2)

Ofer Zelichover · 2012-01-17

Hi,

There are 2 way to do this:
1. use the getNodeByName() function:
if (getNodeByName (syntax_prefix + "body" + syntax_suffix)) == undefined then
(
)

2. use execute:
if (execute ("$'" + syntax_prefix + "body" + syntax_suffix + "'")) == undefined then
(
)

hOpe this helps,
o

kuroiei · 2012-01-18

Works like a charm, thank you very much! (used the second option)