Problem to spawn object

So guys, i following this tutorial http://www.coronalabs.com/blog/2011/09/14/how-to-spawn-objects-the-right-way/ and i’m trying to spawn a simple object on my game, but i keep getting the following error:

Attempt to index local ‘monstro’ (a nil value)

This is my code

 local spawnTable = {} local function spawnObj(params) local monstro = display.newImage("params.image") monstro.objTable = params.objTable monstro.index = #monstro.objTable + 1 monstro.myName = "Object :" .. monstro.index monstro.objTable[monstro.index] = monstro return monstro end for i = 1, 2 do local spawns = spawnObj({ image = "images/orc.png", objTable = spawnTable, }) end for i = 1, #spawnTable do print(spawnTable[i].myName) end

Try removing the quotes from display.newImage(“params.image”).  It should be display.newImage(params.image).  Because you had the quotes, it looks for a file called params.image, which doesn’t exist, which causes monstro to be nil, hence the error.

  • Andrew

Thanks for the quick answer!

Try removing the quotes from display.newImage(“params.image”).  It should be display.newImage(params.image).  Because you had the quotes, it looks for a file called params.image, which doesn’t exist, which causes monstro to be nil, hence the error.

  • Andrew

Thanks for the quick answer!