I’m trying to use this code:
local a = {}
local b = {}
for i = 1,4 do
a[i] = display.newImage("a.png")
a[i].x = math.random(100)
physics.addBody(a[i], {bounce=0.75, radius=50})
a[i]:applyAngularImpulse(10)
a[i]:applyLinearImpulse(xrand, yrand, a[i].x, a[i].y)
a[i]:addEventListener("touch", eventA)
b[i] = display.newImage("b.png")
b[i].x = math.random(100)
physics.addBody(b[i], {bounce=0.75, radius=50})
b[i]:applyAngularImpulse(10)
b[i]:applyLinearImpulse(xrand, yrand, b[i].x, b[i].y)
b[i]:addEventListener("touch", eventB)
end
and I have two event procedures, eventA and eventB that are defined outside the loop.
Why do “applyAngularImpulse” and “applyLinearImpulse” work on a and b but not “addEventListener”?
If I comment out the two lines with “addEventListener” it works, otherwise I get this error:
Runtime error: assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
/Users/username/Desktop/project/main.lua:44: in main chunk
Thanks in advance. [import]uid: 20731 topic_id: 5268 reply_id: 305268[/import]