images in table won't remove

Hi All,

I’m working on my second app and I’m trying to create efficient code so I’m using modules and tables. In this project I have students clicking on directional arrows to make a robot go through a course, then when the robot finishes the course, they press the “clear” button to remove all of the stored robot movements. (as they click the directional arrows, a visual representation of what they have clicked appears on the screen). Everything is working fine except the removal of the images that show what they have clicked. To show the initial images I am doing:

function turnImages()  
if  
introduction.turn1 == "forward" then  
 firstImage = display.newImage(imageTable[1])  
 firstImage.x= 50; firstImage.y = 30  
else if introduction.turn1 == "right" then  
firstImage = display.newImage(imageTable[2])   
firstImage.x= 50; firstImage.y = 30  
else if introduction.turn1 == "backward" then   
firstImage = display.newImage(imageTable[3])  
firstImage.x= 50; firstImage.y = 30  
else if introduction.turn1 == "left" then  
firstImage.x= 0; firstImage.y = 0 else if  
introduction.turn1 == nil then  
firstImage = display.newImage(imageTable[5])  
end  
end  
end  
end  
  
end  

and I have tried several methods to remove such as firstImage:removeSelf(), imageTable = {}, and the fifth image is just an invisible square (thinking I could replace the first choice with this) but nothing seems to work.

Can someone point me toward the correct method?

Thanks [import]uid: 48122 topic_id: 19470 reply_id: 319470[/import]

use a for loop to remove all your data in table
[lua]for i=1,#table do
display.remove(table[i]) – get rid of images
table[i] = nil – clear the table
end[/lua]

or if it doesnt work, then reverse loop
for i=#table,1,-1 do

or you can insert all your images in the displayGroup and then clear all of them from screen with just " group:removeSelf() " [import]uid: 16142 topic_id: 19470 reply_id: 75126[/import]

Awesome! Thank you! [import]uid: 48122 topic_id: 19470 reply_id: 75131[/import]