redefine variable after layer creation

hi,

this little script will make a box and look for a "test_layer" to be parented to.
if the layer not exist it will create one, if it exist it whill parent the box to it.

my problem is that if this layer not exist i can't put the object on it after creation if i do not redefine the variable, it actually doesn't read the "lay" variable anymore and print me undefined instead of .

do you have any tips? thanks!

fn boxlayer x y z =
(	
	b= box width:x length:y height:z name:"test_box"
 
	lay = layermanager.getlayerfromname "test_layer"        
	n_lay = layermanager.newlayerfromname "test_layer"
 
	if lay == undefined do n_lay							---------this looks for "test_layer" and create a new one if needed 
 
--	lay = layermanager.getlayerfromname "test_layer"           	  		---------uncomment this will  make it work, why do i need to redefine the variable?
 
	if lay != undefined do (lay.addnode b)
 
 
)
 
boxlayer 100 100 50

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pixamoon's picture

`

Hi,

This should help:

fn boxlayer x y z =
(	
	local b = box width:x length:y height:z name:"test_box"
	local lay = layermanager.getlayerfromname "test_layer"
 
	if lay == undefined do 
		lay = layermanager.newlayerfromname "test_layer"
 
	if lay != undefined do lay.addnode b
)

boxlayer 100 100 50

Best,
Pixamoon

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.