help on script

Hello
I do a little script and it worked. I forgot to save last changes and now it didn't work anymore..
If anybody can help.
It clone selected object and if i'm not happy with result I can delete these objects.
It is when I press DEL button I get an error...
-----------------
nl = $
PP = nl.pos
try destroyDialog rlslice catch()
global rlslice = rollout rlslice "copy exponL"
(
spinner NB "NB " width:60 range:[2,1000,10] type:#integer
spinner DISTX "DISTz " width:60 range:[.0001,100000,1] type:#float
spinner spX "corr " width:60 range:[.0001,100000,1] type:#float
button GO "GO"
button DEL "DEL"

on GO pressed do
(
newObj=#()
repX = DISTX.value + spX.value

for i=1 to NB.value do
(
newObj[i] = instance nl
nl.pos = nl.pos + [0,0,repX]
repX = repX + spX.value

)
)
on DEL pressed do
(
for a in newObj do ( delete a )
nl.pos = PP
)
)
createDialog rlslice 160 200
-----------------------------------------

Comments

Comment viewing options

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

Thanks you very much for your

Thanks you very much for your help and tips.
Merry chrismas and happy holidays (if any) :-)

miauu's picture

.

Thank you.

Happy Holidays to you too. :)

miauu's picture

.

-----------------
(	
	try destroyDialog rlslice catch()
	global rlslice = rollout rlslice "copy exponL"
	(
		local nl = $
		local PP = nl.pos
		local repX = undefined
		local newObj = #()
 
		spinner NB "NB " width:60 range:[2,1000,10] type:#integer
		spinner DISTX "DISTz " width:60 range:[.0001,100000,1] type:#float
		spinner spX "corr " width:60 range:[.0001,100000,1] type:#float
		button createInstances "GO"
		button DEL "DEL"
 
		on createInstances pressed do
		(
			newObj=#()
			repX = DISTX.value + spX.value
 
			for i=1 to NB.value do
			(
				newObj[i] = instance nl
				nl.pos = nl.pos + [0,0,repX]
				repX = repX + spX.value
 
			)
		)
		on DEL pressed do
		(
			if newObj.count != 0 do
			(
				for a in newObj do ( delete a )
				nl.pos = PP
			)
		)
	)
	createDialog rlslice 160 200
)
-----------------------------------------

Some advices:
- when you write code and you see that a word is colored with different color than the rest of your words, this means that this word is a "specia" word. For example, in your code you give the name "GO" to one of your buttons. As you can se this word is colored with different color than the "DEL" word.
- as you wrote the script the "nl" and "PP" variables becomes global. This may causes problems, because other scripts may use the same variables and when they are global, the scripts will overwrites those variables.
- when you works with arrays ia a good practice first to check if those arrays are not empty.

Comment viewing options

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