removing Images falling randomly ?

In my project i have imagines falling down with a timer , when the timer stop my imagines should disappear but still falling down,
How do I use the remove function self and all at once at the end of time ? how can make all imagines disappears at the same time when the timer is over ? [import]uid: 180288 topic_id: 34884 reply_id: 334884[/import]

Are you using transition.to() to move your items? [import]uid: 199310 topic_id: 34884 reply_id: 138640[/import]

Hi Rob ,
Thanks for all you help,

Yes Im using Transition,
here is part of my coding project about the timer and the imagines still falling and appears in screen even when the timer stopped.

local function updateTime (event) – FUNCTION TIMER
if categoria.text ~= " " then
secsText = secsText + 1
if secsText < 10 then
secsText = “0” …secsText
elseif secsText > 59 then
secsText = 00
minsText = minsText+1
end
timeText.text = minsText … “:” …secsText
if minsText == 1 and secsText == 00 then – TIMER AND STOP
audio.play(finGame)
timer.cancel( event.source )
timer.pause(objetoTimer1)
timer.pause(objetoTimer2)
timer.pause(objetoTimer3)
timer.pause(wordTimer)
categoria.text = " "
secsText = 0
minsText = 0
scoreTexto.text = “Score: 0”
timeText.text = “00:00”
cargarScore()
posicionNivel = “primer”
end
end
return true
end
[import]uid: 180288 topic_id: 34884 reply_id: 138736[/import]

First, I’ve made a little change to your could which should help you, though it has nothing to do with the question you’re asking:

local function updateTime (event) -- FUNCTION TIMER  
 if categoria.text ~= " " then  
 secsText = secsText + 1  
 if secsText \> 59 then  
 secsText = 0  
 minsText = minsText+1  
 end  
  
 timeText.text = string.format("%02d:%02d", minsText, secsText)  
  
 if minsText == 1 and secsText == 0 then -- TIMER AND STOP  
 audio.play(finGame)  
 timer.cancel( event.source )  
 timer.pause(objetoTimer1)  
 timer.pause(objetoTimer2)  
 timer.pause(objetoTimer3)  
 timer.pause(wordTimer)  
 categoria.text = " "  
 secsText = 0  
 minsText = 0  
 scoreTexto.text = "Score: 0"  
 timeText.text = "00:00"  
 cargarScore()  
 posicionNivel = "primer"  
 end  
 end  
 return true  
end  

It’s really helpful when you post code to use <code> and </code> tags at the beginning and ending of the code you’re typing in.

The changes I made are around how you are trying to work with number and strings and I think a little primer is in order.

Lua is a (for the most part) typeless language. In other words any variable can be a string of characters at one moment and then a number the next. This is actually a bad thing for new programmers because it lets you try to use the same variable multiple ways. For instance, you were doing:

secsText = secsText + 1  

Which is fine, secsText is a number at that point and you can do math with it. But then you did this:

if secsText \< 10 then  
 secsText = "0" .. secsText  
...  

Lua turned the number variable secsText into a string variable with the string “0” + whatever the previous value of secsText was. It lets you get away with this because it will convert numbers to strings and back and forth, but its a bad habit to get into.

Later you also were doing numbers like secsText = 00

That isn’t a real number, but again Lua protected you and turned it into a numeric 0, changing secsText from a string back to a number.

I want you to learn about the function string.format(). It allows you to make a string out of other values, but the cool thing is you can say how to format the variables that make up the string. In this case %02d says I want to put a number (without decimal places) where that string is, but I only want it to take up 2 spaces and if it’s not going to fill two spaces, add a 0 in front of it automatically. This string.format() function lets you keep your secsText and minsText as numbers.

Now for your real question, how to remove all these objects, and I have more questions than answers still.

What are the objects?
How are they created?
You said you are using transition.to to move them/ Can we see that code?
What is calling this function?

[import]uid: 199310 topic_id: 34884 reply_id: 138741[/import]

Hey Rob,

Here’s what i have in my project :

function getRandomStar(event) --FUNCION DE MOSTRAR IMAGENES ALEATORIAMENTE
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,ancho) – Set starting point of star at a random X position
randomStar.y = - 20 – Start the star off screen
randomStar.rotation = math.random(0,360) – Rotate the object
starMove = transition.to(randomStar, {time=randomStar.movementSpeed, y=alto-80,
onComplete = function(self) self.parent:remove(self); self = nil; end}) – Move the star
randomStar.name = temp.name
randomStar:addEventListener(“tap”,puntos)
end

function startGame()
objetoTimer1 = timer.performWithDelay(500,getRandomStar, 0)
objetoTimer2 = timer.performWithDelay(800,getRandomStar, 0)
objetoTimer3 = timer.performWithDelay(1000,getRandomStar, 0)
wordTimer = timer.performWithDelay(4500,getWord, 0)
timer.performWithDelay(1000, updateTime, 0)
end

grupo.alpha = 0

I already created a function with a table with all object get storage and saved and makes all object fall randomly in the screen this function works together with a timer so when the timer is over the timer of the object stop too ( the codes sent you in the last message ) but my problems is the object still falling in the screen even when the timer is over ? I know I need to use remove function but I don’t know how ? and also when the time os over i want the object stop falling and appears in the screen

thanks [import]uid: 180288 topic_id: 34884 reply_id: 138865[/import]

Rob
Rob, in the following lines of code that are inside are getRandomStar function

(starMove = transition.to(randomStar, {time=randomStar.movementSpeed, y=alto-80,
onComplete = function(self) self.parent:remove(self); self = nil; end}) – Move the star)

I use onComplete call a function to remove objects when they reach the bottom of the screen. How do I use the same codes or anything like that when time runs out without having to wait until the objects reach the end of the screen.

thanks [import]uid: 180288 topic_id: 34884 reply_id: 138881[/import]

I created a quick app using your creation code (using a circle instead of a star) and that code is successfully removing the stars when the transition ends. Looks like things should be working. [import]uid: 199310 topic_id: 34884 reply_id: 138905[/import]

Are you using transition.to() to move your items? [import]uid: 199310 topic_id: 34884 reply_id: 138640[/import]

Hi Rob ,
Thanks for all you help,

Yes Im using Transition,
here is part of my coding project about the timer and the imagines still falling and appears in screen even when the timer stopped.

local function updateTime (event) – FUNCTION TIMER
if categoria.text ~= " " then
secsText = secsText + 1
if secsText < 10 then
secsText = “0” …secsText
elseif secsText > 59 then
secsText = 00
minsText = minsText+1
end
timeText.text = minsText … “:” …secsText
if minsText == 1 and secsText == 00 then – TIMER AND STOP
audio.play(finGame)
timer.cancel( event.source )
timer.pause(objetoTimer1)
timer.pause(objetoTimer2)
timer.pause(objetoTimer3)
timer.pause(wordTimer)
categoria.text = " "
secsText = 0
minsText = 0
scoreTexto.text = “Score: 0”
timeText.text = “00:00”
cargarScore()
posicionNivel = “primer”
end
end
return true
end
[import]uid: 180288 topic_id: 34884 reply_id: 138736[/import]

Hi Rob,
right! the procedure works well. The detail is that when time stops in 59seconds the last objects are falling and I have to wait for the objects to reach the end of the screen to disappear .
I implemented conditions IF but I don´t have good results.

if secsText <= 50 then
starMove = transition.to(randomStar, {time=randomStar.movementSpeed, y= height,
onComplete = removeObjects}) – Move the objects
elseif secsText >= 51 then
starMove = transition.to(randomStar, {time=7000, y=alto/2 - 50,
onComplete = removeObjects}) – Move the objects
end

All what I want is the objects disappear at the same time when the time stop and don´t have to wait for the transition, y=height [import]uid: 180288 topic_id: 34884 reply_id: 139274[/import]

First, I’ve made a little change to your could which should help you, though it has nothing to do with the question you’re asking:

local function updateTime (event) -- FUNCTION TIMER  
 if categoria.text ~= " " then  
 secsText = secsText + 1  
 if secsText \> 59 then  
 secsText = 0  
 minsText = minsText+1  
 end  
  
 timeText.text = string.format("%02d:%02d", minsText, secsText)  
  
 if minsText == 1 and secsText == 0 then -- TIMER AND STOP  
 audio.play(finGame)  
 timer.cancel( event.source )  
 timer.pause(objetoTimer1)  
 timer.pause(objetoTimer2)  
 timer.pause(objetoTimer3)  
 timer.pause(wordTimer)  
 categoria.text = " "  
 secsText = 0  
 minsText = 0  
 scoreTexto.text = "Score: 0"  
 timeText.text = "00:00"  
 cargarScore()  
 posicionNivel = "primer"  
 end  
 end  
 return true  
end  

It’s really helpful when you post code to use <code> and </code> tags at the beginning and ending of the code you’re typing in.

The changes I made are around how you are trying to work with number and strings and I think a little primer is in order.

Lua is a (for the most part) typeless language. In other words any variable can be a string of characters at one moment and then a number the next. This is actually a bad thing for new programmers because it lets you try to use the same variable multiple ways. For instance, you were doing:

secsText = secsText + 1  

Which is fine, secsText is a number at that point and you can do math with it. But then you did this:

if secsText \< 10 then  
 secsText = "0" .. secsText  
...  

Lua turned the number variable secsText into a string variable with the string “0” + whatever the previous value of secsText was. It lets you get away with this because it will convert numbers to strings and back and forth, but its a bad habit to get into.

Later you also were doing numbers like secsText = 00

That isn’t a real number, but again Lua protected you and turned it into a numeric 0, changing secsText from a string back to a number.

I want you to learn about the function string.format(). It allows you to make a string out of other values, but the cool thing is you can say how to format the variables that make up the string. In this case %02d says I want to put a number (without decimal places) where that string is, but I only want it to take up 2 spaces and if it’s not going to fill two spaces, add a 0 in front of it automatically. This string.format() function lets you keep your secsText and minsText as numbers.

Now for your real question, how to remove all these objects, and I have more questions than answers still.

What are the objects?
How are they created?
You said you are using transition.to to move them/ Can we see that code?
What is calling this function?

[import]uid: 199310 topic_id: 34884 reply_id: 138741[/import]

You could keep track of the transitions and then cancel them when your time runs out. The transition.to function returns a pointer to the transition that you could store in a table and then when your time is up you could go through and kill them.

[import]uid: 199310 topic_id: 34884 reply_id: 139277[/import]

Hey Rob,

Here’s what i have in my project :

function getRandomStar(event) --FUNCION DE MOSTRAR IMAGENES ALEATORIAMENTE
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,ancho) – Set starting point of star at a random X position
randomStar.y = - 20 – Start the star off screen
randomStar.rotation = math.random(0,360) – Rotate the object
starMove = transition.to(randomStar, {time=randomStar.movementSpeed, y=alto-80,
onComplete = function(self) self.parent:remove(self); self = nil; end}) – Move the star
randomStar.name = temp.name
randomStar:addEventListener(“tap”,puntos)
end

function startGame()
objetoTimer1 = timer.performWithDelay(500,getRandomStar, 0)
objetoTimer2 = timer.performWithDelay(800,getRandomStar, 0)
objetoTimer3 = timer.performWithDelay(1000,getRandomStar, 0)
wordTimer = timer.performWithDelay(4500,getWord, 0)
timer.performWithDelay(1000, updateTime, 0)
end

grupo.alpha = 0

I already created a function with a table with all object get storage and saved and makes all object fall randomly in the screen this function works together with a timer so when the timer is over the timer of the object stop too ( the codes sent you in the last message ) but my problems is the object still falling in the screen even when the timer is over ? I know I need to use remove function but I don’t know how ? and also when the time os over i want the object stop falling and appears in the screen

thanks [import]uid: 180288 topic_id: 34884 reply_id: 138865[/import]

Rob
Rob, in the following lines of code that are inside are getRandomStar function

(starMove = transition.to(randomStar, {time=randomStar.movementSpeed, y=alto-80,
onComplete = function(self) self.parent:remove(self); self = nil; end}) – Move the star)

I use onComplete call a function to remove objects when they reach the bottom of the screen. How do I use the same codes or anything like that when time runs out without having to wait until the objects reach the end of the screen.

thanks [import]uid: 180288 topic_id: 34884 reply_id: 138881[/import]

I created a quick app using your creation code (using a circle instead of a star) and that code is successfully removing the stars when the transition ends. Looks like things should be working. [import]uid: 199310 topic_id: 34884 reply_id: 138905[/import]

Hi Rob,
right! the procedure works well. The detail is that when time stops in 59seconds the last objects are falling and I have to wait for the objects to reach the end of the screen to disappear .
I implemented conditions IF but I don´t have good results.

if secsText <= 50 then
starMove = transition.to(randomStar, {time=randomStar.movementSpeed, y= height,
onComplete = removeObjects}) – Move the objects
elseif secsText >= 51 then
starMove = transition.to(randomStar, {time=7000, y=alto/2 - 50,
onComplete = removeObjects}) – Move the objects
end

All what I want is the objects disappear at the same time when the time stop and don´t have to wait for the transition, y=height [import]uid: 180288 topic_id: 34884 reply_id: 139274[/import]

You could keep track of the transitions and then cancel them when your time runs out. The transition.to function returns a pointer to the transition that you could store in a table and then when your time is up you could go through and kill them.

[import]uid: 199310 topic_id: 34884 reply_id: 139277[/import]