Notifications
Clear all
[Closed] question about array
Sep 01, 2010 11:05 pm
I’m trying to create a button that generates spheres… and these spheres are part of an array, a second button to delete all spheres at once.
this is code:
rollout TestArray "Test Array"
(
local objArray
button b01 "Create"
button b02 "Delete"
on b01 pressed do
(
ObjArray = #()
ObjTest = Sphere()
append ObjArray ObjTest
)
on b02 pressed do
(
delete ObjArray
)
)
createDialog TestArray
Only deletes last sphere, why?
1 Reply
Sep 01, 2010 11:05 pm
rollout TestArray "Test Array"
(
[b]local objArray = #()[/b]
button b01 "Create"
button b02 "Delete"
on b01 pressed do
(
ObjTest = Sphere()
append ObjArray ObjTest
)
on b02 pressed do
(
delete objArray
[b]objArray = #()[/b]
)
)
createDialog TestArray
On your old script, everytime you created a new sphere you called objArray = #() which resets the array. So the array would always have one item no matter how many spheres you were creating. So I just got rid of that line, and also added a line to reset the array after you deleted it (otherwise it crashes if you hit delete twice)