Asteroids not showing?

Hi. Gotta (hopefully) quick question here. I was following the Space Explorer tutorial up until the asteroids were supposed to appear. I have the background and ship, but no asteroids appear. No clue what I did. Any help please? Thanks.

It’s generally easier if you share your code by using the code formatting tool here on the forums.

Also, if that is all of your code, then it simply seems like you aren’t calling the function that creates the asteroids. I would presume that the tutorial continues somewhere and that is explained there.

Basically, what you’ve got now is the function where a single new asteroid is created and all you need to do to create a single asteroid is to call it, i.e. add the line: 

createAsteroid()

anywhere below the createAsteroid function to call the function.

Thanks for the fast response!

But, now only the asteroids successfully come from the left. I get error messages 2/3rds of the time.

a table is expected at 109 and 114. Apologies- I understand the basics of Lua and tables, but I’m very new to Corona SDK. I don’t see what the error speaks of, exactly. I did change the code slightly.

 local function updateText() livesText.text = "Lives: " ..lives scoreText.text = "Score: "..score end local function createAsteroid() local newAsteroid = display.newImageRect( maingroup, objectSheet, 1, 102, 85 ) table.insert( asteroidsTable, newAsteroid ) physics.addBody( newAsteroid, "dynamic", {radius=40, bounce=0.8} ) newAsteroid.myName = "asteroid" local whereFrom = math.random(3) if (whereFrom == 1) then -- left newAsteroid.x = -60 newAsteroid.y = math.random( 500 ) newAsteroid:setLinearVelocity( math.random( 40, 120 ), math.random( 20, 60 )) elseif (whereFrom == 2) then newAsteroid.x = math.random(display.contentWidth) newAsteroid.y = -60 newAsteroid.setLinearVelocity( math.random (-40, 40), math.random( 40, 120 )) else newAsteroid.x = display.contentWidth + 60 newAsteroid.y = math.random( 500 ) newAsteroid.setLinearVelocity( math.random(-120, 40), math.random( 20, 60 )) end end createAsteroid()

 

Use ”:” not ”.” with methods.

Got it! Thanks!

It’s generally easier if you share your code by using the code formatting tool here on the forums.

Also, if that is all of your code, then it simply seems like you aren’t calling the function that creates the asteroids. I would presume that the tutorial continues somewhere and that is explained there.

Basically, what you’ve got now is the function where a single new asteroid is created and all you need to do to create a single asteroid is to call it, i.e. add the line: 

createAsteroid()

anywhere below the createAsteroid function to call the function.

Thanks for the fast response!

But, now only the asteroids successfully come from the left. I get error messages 2/3rds of the time.

a table is expected at 109 and 114. Apologies- I understand the basics of Lua and tables, but I’m very new to Corona SDK. I don’t see what the error speaks of, exactly. I did change the code slightly.

 local function updateText() livesText.text = "Lives: " ..lives scoreText.text = "Score: "..score end local function createAsteroid() local newAsteroid = display.newImageRect( maingroup, objectSheet, 1, 102, 85 ) table.insert( asteroidsTable, newAsteroid ) physics.addBody( newAsteroid, "dynamic", {radius=40, bounce=0.8} ) newAsteroid.myName = "asteroid" local whereFrom = math.random(3) if (whereFrom == 1) then -- left newAsteroid.x = -60 newAsteroid.y = math.random( 500 ) newAsteroid:setLinearVelocity( math.random( 40, 120 ), math.random( 20, 60 )) elseif (whereFrom == 2) then newAsteroid.x = math.random(display.contentWidth) newAsteroid.y = -60 newAsteroid.setLinearVelocity( math.random (-40, 40), math.random( 40, 120 )) else newAsteroid.x = display.contentWidth + 60 newAsteroid.y = math.random( 500 ) newAsteroid.setLinearVelocity( math.random(-120, 40), math.random( 20, 60 )) end end createAsteroid()

 

Use ”:” not ”.” with methods.

Got it! Thanks!