game

OK let me brief up the code below is different about enemy ships hovering and automatically firing.

--setting physics local physics= require( "physics") physics.start() physics.setGravity(0,0) local w,h=display.contentWidth,display.contentHeight -- Hide status bar display.setStatusBar( display.HiddenStatusBar ) -- Seed the random number generator math.randomseed( os.time() ) --initializing variables local enemyTable={} local numEnemy=0 local mainGroup=display.newGroup() local function loadEnemy() numEnemy=#enemyTable+1 local newEnemy=display.newRect(mainGroup,w/2,20+(math.random(1,3)\*30),30,30) newEnemy:setFillColor(1,0.2,0.2,1) table.insert(enemyTable,newEnemy) physics.addBody( newEnemy,"dynamic" ) newEnemy.myName="enemy" mewEnemy:setLinearVelocity((math.random(10,70)),0) local function fireEnemyBullet() local newEnemyBullet=display.newImage(mainGroup,"enemyBullet.png",newEnemy.x,newEnemy.y) physics.addBody( newEnemyBullet,"dynamic" ) newEnemyBullet.isBullet=true newEnemyBullet.myName="enemyBullet" newEnemyBullet.toBack()--keeps below the enemy shipBlast transition.to( newEnemyBullet,{y=h+40,time=700,onComplete=function() display.remove(newEnemyBullet) end }) end fireEnemyBullet() end local function gameLoop() loadEnemy() for i=#enemyTable,1,-1 do--#tells the number of object in enemyTable local thisEnemy=enemyTable[i] if(thisEnemy.x\>=w+40) then display.remove( thisEnemy ) table.remove( enemyTable, i ) end end end timer.performWithDelay( 500, gameloop ,0 )

The code here is only part of a big program but since it was not working I tried to tried to break it down to small section to look for the actual fault now when I compile the above program  it shows no error but it show a dark screen help me out

I understand that English isn’t your first language, it isn’t mine either, but please try to make your posts clearer and easier to understand. For instance, the title “game” doesn’t explain anything and many users are just going to ignore your post because of that. I also had to read your post three times until I believe that I understood what you were saying.

Please read this post by roaminggamer: https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

Are there any messages in your console log?

Rob

Hi for the title I literally can’t understand what should I write let me explain it again actually I am trying to prepare a level 2 of the star explorer game( which is taught in corona) where in place of asteroid ship will be hovering from left to right at the same time fire bullets ,the snippet given above is part of the entire level but there was error so tried to break the code into small independent section and the code involves around the firing mechanism of enemy. I hope now you understand whats the problem now when I compile the problem what happens is the the code runs without error but the screen in simulator remains black.

To “coronaRob”  no messages please compile it yourself if you can find some problem because I am not able to find the actual problem. 

Hey @ashutoshpanda840 – looks like you’ve got a few minor syntax errors that are the problem.

The main one that’s stopping anything from appearing is in your gameloop timer. The “L” in the function is capitalized:

timer.performWithDelay( 500, gameloop, 0 ) --NEEDS TO BE: timer.performWithDelay( 500, gameLoop, 0 ) --NOTICE THE CAPITAL "L" IN "gameLoop"

Once you change that you’ll see a couple other errors in the console, also related to minor syntax issues. These are:

mewEnemy:setLinearVelocity --NEEDS TO BE: newEnemy:setLinearVelocity --NOTICE THE FIRST LETTER WAS AN "M"

and

newEnemyBullet.toBack() --NEEDS TO BE: newEnemyBullet:toBack() --NOTICE THE PUNCTUATION

Hope that helps!

I can’t compile it for myself. I don’t have all the resources to build the app. If you want the community to help you, provide everything needed in a .zip file and share it with us.

Rob

I understand that English isn’t your first language, it isn’t mine either, but please try to make your posts clearer and easier to understand. For instance, the title “game” doesn’t explain anything and many users are just going to ignore your post because of that. I also had to read your post three times until I believe that I understood what you were saying.

Please read this post by roaminggamer: https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

Are there any messages in your console log?

Rob

Hi for the title I literally can’t understand what should I write let me explain it again actually I am trying to prepare a level 2 of the star explorer game( which is taught in corona) where in place of asteroid ship will be hovering from left to right at the same time fire bullets ,the snippet given above is part of the entire level but there was error so tried to break the code into small independent section and the code involves around the firing mechanism of enemy. I hope now you understand whats the problem now when I compile the problem what happens is the the code runs without error but the screen in simulator remains black.

To “coronaRob”  no messages please compile it yourself if you can find some problem because I am not able to find the actual problem. 

Hey @ashutoshpanda840 – looks like you’ve got a few minor syntax errors that are the problem.

The main one that’s stopping anything from appearing is in your gameloop timer. The “L” in the function is capitalized:

timer.performWithDelay( 500, gameloop, 0 ) --NEEDS TO BE: timer.performWithDelay( 500, gameLoop, 0 ) --NOTICE THE CAPITAL "L" IN "gameLoop"

Once you change that you’ll see a couple other errors in the console, also related to minor syntax issues. These are:

mewEnemy:setLinearVelocity --NEEDS TO BE: newEnemy:setLinearVelocity --NOTICE THE FIRST LETTER WAS AN "M"

and

newEnemyBullet.toBack() --NEEDS TO BE: newEnemyBullet:toBack() --NOTICE THE PUNCTUATION

Hope that helps!

I can’t compile it for myself. I don’t have all the resources to build the app. If you want the community to help you, provide everything needed in a .zip file and share it with us.

Rob