Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Error problem
Started by de.pdahowdy Jan 21 2019 10:57 PM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

de.pdahowdy

[GLOBAL: userInfoPane.html]
de.pdahowdy
  • Observer

  • 2 posts
  • Corona SDK

This is giving me an Error in 82
main.lua:82: ERROR: table expected. If this is a function call, you might have used '.' instead of ':'
Stack traceback:
  [C]: in function 'addBody'
  main.lua:82: in function 'loadAsteroid'
  main.lua:165: in function '_listener'
  ?: in function <?:167>
  ?:in function <?:221>
 Any Ideas?
 

local function loadAsteroid()
numAsteroids= numAsteroids +1
asteroidsTable[numAsteroids] = display.newImage("asteroids1-1a.png")
(82) physics.addBody(asteroidsTable[numAsteroids], {density=1,friction=0.4,bounce=1})
local whereFrom = math.random(3)
asteroidsTable[numAsteroids].myName="asteroid"
--Spawns
if(whereFrom==1) then
asteroidsTable[numAsteroids].x = -50
asteroidsTable[numAsteroids].y = (math.random( display.contentHeight *.75))
transition.to(asteroidsTable[numAsteroids], {x= (display.contentWidth +100), y=(math.random( display.contentHeight)), time =(math.random( 5000, 10000))})
elseif(whereFrom==2) then
asteroidsTable[numAsteroids].x = (math.random( display.contentWidth))
asteroidsTable[numAsteroids].y = -30
transition.to(asteroidsTable[numAsteroids], {x= (math.random(display.contentWidth)), y=(display.contentHeight + 100), time =(math.random(5000, 10000))})
elseif(whereFrom==3) then
asteroidsTable[numAsteroids].x = display.contentWidth+50
asteroidsTable[numAsteroids].y = (math.random( display.contentHeight *.75))
transition.to(asteroidsTable[numAsteroids], {x= -100, y=(math.random(display.contentHeight)), time =(math.random(5000, 10000))})
end
end


local function gameLoop()
updateText()
(165) loadAsteroid()
--remove old shots fired so they don't stack
for i = 1, table.getn(shotTable) do
if (shotTable[i].myName ~= nil and shotTable[i].age < maxShotAge) then
shotTable[i].age = shotTable[i].age + tick
elseif (shotTable[i].myName ~= nil) then
shotTable[i]:removeSelf()
shotTable[i].myName=nil
end
end
end

 



[TOPIC: post.html]
#2

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 877 posts
  • Corona SDK

It doesn't look like your code goes to 165 or even 82 lines.

 

Re-post the full main.lua code and format it with line numbers so we can see better.



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,263 posts
  • Enterprise

Are there additional messages in the device's (or simulator's) console log, like a warning that it couldn't find asteroids1-1a.png?

 

That error likely means that asteroidsTable[numAsteroids] isn't a valid display object.

 

Rob




[topic_controls]
[/topic_controls]