Corona SDK(LUA) - attempt to call upvalue 'spawnEnemy'(a nil value) -


i trying add eventlistener object, should disappear when tap on it. error mentioned in title. here whole code @ point :

-- housekeeping stuff  display.setstatusbar(display.hiddenstatusbar)  local centerx = display.contentcenterx local centery = display.contentcentery  -- set forward references  local spawnenemy  -- preload audio  -- create play screens  local function createplayscreen()      local bg = display.newimage("background.png")     bg.y = 130     bg.x = 100     bg.alpha = 0      local planet = display.newimage("planet.png")     planet.x = centerx     planet.y = display.contentheight +60     planet.alpha = 0      transition.to( bg,  { time = 2000, alpha = 1,  y = centery, x = centerx } )      local function showtitle()         local gametitle = display.newimage("gametitle.png")         gametitle.alpha = 0         gametitle:scale (4, 4)         transition.to( gametitle, { time = 500, alpha = 1, xscale = 1, yscale = 1 })         spawnenemy()     end      transition.to( planet,  { time = 2000, alpha = 1,  y = centery, oncomplete = showtitle } ) end  -- game functions  local function shipsmash(event)      local obj = event.target     display.remove( obj )  end  local function spawnenemy()      local enemy = display.newimage("beetleship.png")     enemy.x = math.random(20, display.contentwidth - 20)     enemy.y = math.random(20, display.contentheight - 20)     enemy:addeventlistener ( "tap", shipsmash )  end   local function startgame()  end   local function planetdamage()  end   local function hitplanet(obj)  end     createplayscreen() startgame() 

and here how error window looks :

enter image description here

i'm kinda new in area(lua programming) sorry maybe dumb syntax error or something, saw error shows after write line of code: enemy:addeventlistener ( "tap", shipsmash )

change local function spawnenemy() function spawnenemy() variable declared earlier. yes, typical lua pitfall beginners.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -