[Closed] Possible to use $ with variable names?
EXAMPLE:
x = "001"
for i = 1 to 100 do
( Sphere radius:5 name:("S"+x) )
^ Works great. Creates 100 spheres named S001 to S100.
BUT how can I select one in the same type of way?
EXAMPLE:
select $("P" + x)
^ DOES NOT WORK
Try the “getNodeByName” function (can be found in “Node Common Properties, Operators, and Methods” in the helpfiles)
You can use the function “getnodebyname” for this
Example :
local someNode = getnodebyname "somename"
most of the time you don’t need/want this because when you create nodes with a script, you should have them stored in a collection anyway. If you create objects in a loop, why would you have to find them later by name?
select $P*
Ah, thanks a ton. Getnodebyname is exactly what I was looking for! :bounce:
you can always execute it as string…
but I think what your’re trying to do is a bit weird…you want to use a variable name but don’t know it? How do you have dynamic variable names in your script?
var="select $"+"p"
execute var
The dynamic variable names is from creating a random number of spheres, and naming them, for example, A1, A2… AN. Then, I could select one via
z = AX (where X is <= N)
select (getnodebyname z)