array problem

I think that the problem is with the array in my function:

local itens = require ( "itens" )  
  
-----------------  
 local a = 0  
 local greenPoof = {}  
 local objetos = {}  
-----------------  
  
-------------------------------//------------------------------  
  
function E\_bomb1Spawn(e)  
 a = a + 1  
  
 objetos[a] = itens.novoItem()  
  
 objetos[a] = greenPoof[a]  
  
 --physics.addBody( objetos[a], "dynamic", { density=1, bounce=0, friction=0.5 } )  
  
  
 hudGroup:insert( objetos[a] )  
  
 objetos[a].collision = onImageCollision  
 objetos[a]:addEventListener("collision", objetos[a])  
 instance2:addEventListener("collision", instance2)   
  
end  

when i try to run my game I get this error:

 level1.lua:1740: ERROR: table expected. If this is a function call, you might have used '.' instead of ':' 

and my line 1740 is:

 hudGroup:insert( objetos[a] ) 

anyone want to give a shot?
thanks [import]uid: 23063 topic_id: 10765 reply_id: 310765[/import]

This looks weird right?

objetos[a] = itens.novoItem()  
  
objetos[a] = greenPoof[a]   

I don’t know what novoItem() does, but maybe you meant:

greenPoof[a] = itens.novoItem()  
  
objetos[a] = greenPoof[a]   

?

-Angelo
[import]uid: 12822 topic_id: 10765 reply_id: 39121[/import]

[code]local onImageCollision = function ( self, event )

if( self.type == “gelo” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+5)
system.vibrate()
if podeSlow then
slowScreen = timer.performWithDelay(10,SlowScreen,1)
end
end

if( self.type == “clock” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+15)
tempo.setTempo (tempo.getTempo()+15)
numRelogios = numRelogios + 1
system.vibrate()
end

if( self.type == “potion” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+10)
system.vibrate()
if reverseLigado == false then
Orevertecontroles = timer.performWithDelay(10,ReverteControles,1)
end
end

if( self.type == “potion2” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+20)
system.vibrate()
if podeReduzirVelocidade then
reduzirVelocidadeScreen = timer.performWithDelay(10,reduzirVelocidade,1)
end
end

if( self.type == “pena” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+10)
end

if( self.type == “morcego” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+25)
end

if( self.type == “gato” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+5)
end

if( self.type == “chapeu” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+20)
numHats = numHats + 1
end

if( self.type == “aranha” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+50)
end

if( self.type == “abobora” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+15)
end

if( self.type == “caveira” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+25)
numCaveiras = numCaveiras + 1
end

if( self.type == “caveira2” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+60)
numCaveiras = numCaveiras + 1
system.vibrate()
if podeFast then
fastScreen = timer.performWithDelay(10,FastScreen,1)
end
end

– Poof code below –
if poofTween then transition.cancel( poofTween ); end

greenPoof[a].x = self.x; greenPoof[a].y = self.y
greenPoof[a].alpha = 0
greenPoof[a].isVisible = true

local complete1 = function (e)
greenPoof[a]:removeSelf()
end

local fadePoof = function(e)
transition.to( greenPoof[a], { time=300, alpha=0, onComplete = complete1 } )
end
poofTween = transition.to( greenPoof[a], { time=100, alpha=1.0, onComplete=fadePoof } )

self.parent:remove( self )
self = nil
end

function E_bomb1Spawn(e)
a = a + 1

objetos[a] = itens.novoItem()
objetos[a].x = 150

greenPoof[a] = display.newImageRect( “imagens/bola.png”, 30, 30 )
greenPoof[a].alpha = 1.0
greenPoof[a].isVisible = false

gameGroup:insert( greenPoof[a] )

–physics.addBody( objetos[a], “dynamic”, { density=1, bounce=0, friction=0.5 } )

hudGroup:insert( objetos[a] )

objetos[a].collision = onImageCollision
objetos[a]:addEventListener(“collision”, objetos[a])
instance2:addEventListener(“collision”, instance2)

end
[/code]

in my game, when a object collide with the ground, he break up
and after 300 miliseconds he removeSelf… but my problem is to do this… what happen when 2 objects collide in the ground, the first object begin the transition to fade in and removeself, but when the second object collide, he stop the first objects removeSelf function
I try to make this “greenPoof” a array and set this to have a ID, one for each object… but i dont know why this isnt working

[code]a = a + 1

objetos[a] = itens.novoItem()
objetos[a].x = 150

greenPoof[a] = display.newImageRect( “imagens/bola.png”, 30, 30 )
greenPoof[a].alpha = 1.0
greenPoof[a].isVisible = false

gameGroup:insert( greenPoof[a] )
[/code] [import]uid: 23063 topic_id: 10765 reply_id: 39177[/import]

I cant see where you define hudGroup as a group [import]uid: 5354 topic_id: 10765 reply_id: 39342[/import]

i just omit some code to not make my post more bigger… my problem isn´t in hudGroup and yes in greenPoof[a]
[import]uid: 23063 topic_id: 10765 reply_id: 39345[/import]

If you strip it down to just the code that is necessary I will have a look tomorrow.

From first read of the code I would use local inside the function when generating new objects / images so the object is unique and inside the scope of the function

then inserting it into an array or table

you cant use an array / a counter as removing the object will alter the makeup of the array

use table insert and #tableName to count the current number of objects in the array

im not sure I would use an array at all for this, I cant see where its needed

anyway off to pub, email me at the email address on www.coronaremote.com and I will have a look tomorrow [import]uid: 5354 topic_id: 10765 reply_id: 39348[/import]

you want that I send you all my code to your check at this email? [import]uid: 23063 topic_id: 10765 reply_id: 39353[/import]

Write a small amount of code that contains just enough code to run and demonstrate the bug. Don’t send all 1700+ lines of code. [import]uid: 5354 topic_id: 10765 reply_id: 39355[/import]

ok but i will need to write the itens.lua too, for make the objects [import]uid: 23063 topic_id: 10765 reply_id: 39360[/import]