Code does not work.

Hey, i started learning corona sdk by making a space invaders game on this tutorial : http://code.tutsplus.com/tutorials/create-a-space-invaders-game-in-corona-implementing-gameplay–cms-22788

i wrote the same code but it doesn’t work, it gives me an error.

the start.lua file is:

local composer = require( "composer" ) local scene = composer.newScene() local startButton -- used to start the game local pulsatingText = require("pulsatingtext") -- A module providing a pulsating text effect local starFieldGenerator = require("starfieldgenerator") -- A module that generates the starFieldGenerator local starGenerator -- An instance of the starFieldGenerator function scene:create( event ) local group = self.view startButton = display.newImage("new\_game\_btn.png",display.contentCenterX,display.contentCenterY) group:insert(startButton) local invadersText = pulsatingText.new("INVADERZ",display.contentCenterX,display.contentCenterY-200,"CONQUEST", 20,group) invadersText:setColor( 1, 1, 1 ) invadersText:pulsate() end function scene:show( event ) local phase = event.phase local previousScene = composer.getSceneName( "previous" ) if(previousScene~=nil) then composer.removeScene(previousScene) end if ( phase == "did" ) then startButton:addEventListener("tap",startGame) end end function scene:hide( event ) local phase = event.phase if ( phase == "will" ) then startButton:removeEventListener("tap",startGame) end end function startGame() composer.gotoScene("gamelevel") end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) return scene

and the pulsatingtext.lua file is:

local composer = require( "composer" ) local scene = composer.newScene() local pulsatingText = {} local pulsatingText\_mt = {\_\_index = pulsatingText} function pulsatingText.new(theText,positionX,positionY,theFont,theFontSize,theGroup) local theTextField = display.newText(theText,positionX,positionY,theFont,theFontSize) local newPulsatingText = { theTextField = theTextField} theGroup:insert(theTextField) return setmetatable(newPulsatingText,pulsatingText\_mt) end function pulsatingText:setColor(r,b,g) self.theTextField:setFillColor(r,g,b) end function pulsatingText:pulsate() transition.to( self.theTextField, { xScale=4.0, yScale=4.0, time=1500, iterations = -1} ) end return pulsatingText return scene

i upload an image with the error i am getting.

thanks for your help!

The pulsatingText should not be part of the composer as it is trying to return the “composer” stuff right now. Try and change pulsatingText to this:

local pulsatingText = {} local pulsatingText\_mt = {\_\_index = pulsatingText} function pulsatingText.new(theText,positionX,positionY,theFont,theFontSize,theGroup) local theTextField = display.newText(theText,positionX,positionY,theFont,theFontSize) local newPulsatingText = { theTextField = theTextField} theGroup:insert(theTextField) return setmetatable(newPulsatingText,pulsatingText\_mt) end function pulsatingText:setColor(r,b,g) self.theTextField:setFillColor(r,g,b) end function pulsatingText:pulsate() transition.to( self.theTextField, { xScale=4.0, yScale=4.0, time=1500, iterations = -1} ) end return pulsatingText

Best regards,

Tomas

The pulsatingText should not be part of the composer as it is trying to return the “composer” stuff right now. Try and change pulsatingText to this:

local pulsatingText = {} local pulsatingText\_mt = {\_\_index = pulsatingText} function pulsatingText.new(theText,positionX,positionY,theFont,theFontSize,theGroup) local theTextField = display.newText(theText,positionX,positionY,theFont,theFontSize) local newPulsatingText = { theTextField = theTextField} theGroup:insert(theTextField) return setmetatable(newPulsatingText,pulsatingText\_mt) end function pulsatingText:setColor(r,b,g) self.theTextField:setFillColor(r,g,b) end function pulsatingText:pulsate() transition.to( self.theTextField, { xScale=4.0, yScale=4.0, time=1500, iterations = -1} ) end return pulsatingText

Best regards,

Tomas