How to remove random objects from storyboard?

I have this code – COMPLETE –

– --==***************************************************************************+±- –
– Music Theory Game
– By Victor M. Barba
– Copyright 2013 – All Rights Reserved

– Version 1.0
– --==***************************************************************************+±- –

local storyboard = require( “storyboard” )
local widget = require “widget”
local scene = storyboard.newScene()
local wrongSound = audio.loadSound( “wrongSound.mp3”)

– --==******************[FUNCTIONS TO GO TO ANOTHER SCENE]**********************+±- –

local function buttonHome()
        storyboard.gotoScene( “home”, “crossFade”, 1000 )    
    return true
end

– --==**************************[CREATE SCENE]**********************************+±- –

function scene:createScene( event )
    local group = self.view
    
    local background = display.newImage( “backgroundRight1.png” )
    
    buttonHome = widget.newButton{
        defaultFile=“buttonHome.png”,
        onRelease = buttonHome
    }
    buttonHome.x = 522
    buttonHome.y = 655

    
    
---------------------------------------------------------------------insert into group----
    
    group:insert ( background )
    group:insert ( buttonHome )

    
end

– --==***************************[ENTER SCENE]**********************************+±- –

function scene:enterScene( event )
    local group = self.view
    
    _W = display.contentWidth;                                      --Returns Screen Width
    _H = display.contentHeight;                                     --Returns Screen Height
local starTable = {}                                                – Set up star table

    function initStar()
    local star1 = {}
    star1.imgpath = “ladyBug.png”;                                  --Set Image Path for Star
    star1.movementSpeed = 10000;                                    --Determines the movement speed of star
    table.insert(starTable, star1);                                 --Insert Star into starTable
    
    local star2 = {}
    star2.imgpath = “bat.png”;
    star2.movementSpeed = 12000;
    table.insert(starTable, star2);                
    
    local star3 = {}
    star3.imgpath = “bee.png”;
    star3.movementSpeed = 14000;
    table.insert(starTable, star3);
    end --END initStar()
    

    
    
    function getRandomStar()
    local temp = starTable[math.random(1, #starTable)]              – Get a random star from starTable
    local randomStar = display.newImage(temp.imgpath)               – Set image path for object
    randomStar.myName = “star”                                      – Set the name of the object to star
    randomStar.movementSpeed = temp.movementSpeed;                  – Set how fast the object will move
    randomStar.x = math.random(0,_W)                                – Set starting point of star at a random X position
    randomStar.y = _H + 50                                          – Start the star off screen
    randomStar.rotation = math.random(0,360)                        – Rotate the object
    starMove = transition.to(randomStar, { time=randomStar.movementSpeed, y=-45,
        onComplete = function(self) self.parent:remove(self); self = nil; end})                                                          – Move the star
    end                                                            --END getRandomStar()
    
    
    function startGame()
    starTimer1 = timer.performWithDelay(1700,getRandomStar, 0)
    starTimer2 = timer.performWithDelay(2300,getRandomStar, 0)
    starTimer3 = timer.performWithDelay(2700,getRandomStar, 0)

    end                                                             --END startGame()

initStar()
startGame()    

    

    
    
end

– --==***************************[EXIT SCENE]**********************************+±- –

function scene:exitScene( event )
    local group = self.view
    
end

– --==**************************[DESTROY SCENE]*********************************+±- –

function scene:destroyScene( event )
    local group = self.view
    
    if buttonHome then
            buttonHome:removeSelf()
            buttonHome = nil
        end
    
    
end

– --==*************************[EVENT LISTENER]*********************************+±- –

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

return scene


---------------------------------------------------FIRST-----------------------------------------------------


It works perfect! but the logic I think, nothing works here, and I don’t know why.

I only have 3 objects “images” – star1, star2, and star3, my logic is that if I just copy this code

local star3 = {}
    star3.imgpath = “bee.png”;
    star3.movementSpeed = 14000;
    table.insert(starTable, star3);
    end --END initStar()

and change that for star4 I will get one more object or image right?N

No, it doesn’t work – So how do I add more stars or objects?


-------------------------------------------------SECOND---------------------------------------------------


When I go to another scene I can make an object or image remove by creating the local star3 first

then on the enter scene I remove the “local” from the star3, and then on the exit scene I put

display.remove (star3)

I tried this here , again, it doesn’t work. So how do I remove all this moving objects when I go to another scene?


-----------------------------------------------------THIRD--------------------------------------------------


And how do I make them move from left to right? or from right to left?

Right now they are moving from bottom to top, only.

Thanks for your help

Victor