Spawn help please?

Hi guys, I’m new to Corona/Programming, and was hoping I could get a little help from the senior programmers if you will.

I have 2 objects falling from the top, my countown functions as soon as they spawn and changes to Go and Win/Fail etc.

Each time I try to change the total amount of objects to spawn, it won’t register and spawns the same number for each.

For example;

O1 = 0  
O2 = 0  
time\_remain = 10  
time\_up = false  
  
total\_object1 = 4  
total\_object2 = 2  
  
ready = true  

That is the top of the page, my timer is linked to Object1, is it supposed to be linked to both?

[code]
local function spawnObject()

local object1= display.newImageRect(“XX.png”, 40, 40)
object1:setReferencePoint(display.CenterReferencePoint)
object1.x = 35; object1.y = 80

–increment O1 for every object1 created
O1 = O1+1

object1:addEventListener(“touch”, object1)

physics.addBody(object1, {density=0.3, friction=0.6, radius=20} )

tmr = timer.performWithDelay(20, spawnObject, total_object1)[/code]

If someone could help me with a table or code that could allow me to control the number of spawn, I’d be extremely grateful.

Thank you [import]uid: 41602 topic_id: 7811 reply_id: 307811[/import]

It’s not clear where you’re calling performWithDelay from, and how and where you’re (presumably) changing the value of total_object1. Maybe we need to see the rest of the relevant code. [import]uid: 3953 topic_id: 7811 reply_id: 27734[/import]

I found this helpful when I was looking at a class based system for spawning objects:

http://www.planetlua.com/journal/2011/1/16/blue-balls-part-1.html [import]uid: 10903 topic_id: 7811 reply_id: 27955[/import]

Going to try something - will post back as soon as possible.

Thank you for the reply, Mark.

Edit: If anyone could start me off on a table to control the spawns of multiple objects(number of spawns), I’d be highly appreciative - I just can’t figure it out.

Thank you! [import]uid: 41602 topic_id: 7811 reply_id: 27935[/import]

Thank you, Crssmn.

Got it sorted now thanks to the link =) [import]uid: 41602 topic_id: 7811 reply_id: 28707[/import]