I'm having this issue, and I can't find a solution:
"level1.lua:161 attempt to index global 'crate' (a nil value)"
It happens when it should change the crate position on line 161, but "centerX + (centerX * event.xGravity" does not return nil, cause the "textMessage" show the correct value.
Code below
-----------------------------------------------------------------------------------------
--
-- level1.lua
--
-----------------------------------------------------------------------------------------
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- include Corona's "physics" library
local physics = require "physics"
physics.start(); physics.pause()
--------------------------------------------
-- Sounds
local shakeSound = audio.loadSound ("shake.mp3")
-- Display, metrics stuff
local centerX = display.contentWidth / 2
local centerY = display.contentHeight / 2
-- forward declarations and other locals
local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth*0.5
-----------------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
--
-- NOTE: Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
-----------------------------------------------------------------------------------------
-- Text parameters
local labelx = 50
local x = 220
local y = 95
local fontSize = 24
local frameUpdate = false -- used to update our Text Color (once per frame)
local xglabel = display.newText( "gravity x = ", labelx, y, native.systemFont, fontSize )
xglabel:setTextColor(255,255,255)
local textMessage = function( str, location, scrTime, size, color, font )
local x, t
size = tonumber(size) or 24
color = color or {255, 255, 255}
font = font or "Helvetica"
-- Determine where to position the text on the screen
if "string" == type(location) then
if "Top" == location then
x = display.contentHeight/4
elseif "Bottom" == location then
x = (display.contentHeight/4)*3
else
-- Assume middle location
x = display.contentHeight/2
end
else
-- Assume it's a number -- default to Middle if not
x = tonumber(location) or display.contentHeight/2
end
scrTime = (tonumber(scrTime) or 3) * 1000 -- default to 3 seconds (3000) if no time given
t = display.newText(str, 0, 0, font, size )
t.x = display.contentWidth/2
t.y = x
t:setTextColor( color[1], color[2], color[3] )
-- Time of 0 = keeps on screen forever (unless removed by calling routine)
--
if scrTime ~= 0 then
-- Function called after screen delay to fade out and remove text message object
local textMsgTimerEnd = function()
transition.to( t, {time = 500, alpha = 0},
function() t.removeSelf() end )
end
-- Keep the message on the screen for the specified time delay
timer.performWithDelay( scrTime, textMsgTimerEnd )
end
return t -- return our text object in case it's needed
end -- textMessage()
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
-- create a grey rectangle as the backdrop
local background = display.newRect( 0, 0, screenW, screenH )
background:setFillColor( 128 )
-- make a crate (off-screen), position it, and rotate slightly
local crate = display.newImage('crate.png') --display.newImageRect( "crate.png", 90, 90 )
crate.x = centerX
crate.y = centerY
crate.rotation = 15
-- add physics to the crate
physics.addBody( crate, { density=1.0, friction=0.3, bounce=0.3 } )
-- create a grass object and add physics (with custom shape)
local grass = display.newImageRect( "grass.png", screenW, 82 )
grass:setReferencePoint( display.BottomLeftReferencePoint )
grass.x, grass.y = 0, display.contentHeight
-- define a shape that's slightly shorter than image bounds (set draw mode to "hybrid" or "debug" to see)
local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 }
physics.addBody( grass, "static", { friction=0.3, shape=grassShape } )
-- all display objects must be inserted into group
group:insert( background )
group:insert( grass)
group:insert( crate )
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
physics.start()
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
physics.stop()
end
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
package.loaded[physics] = nil
physics = nil
end
-- Accelerometer
local function onAccelerate( event )
-- Move our object based on the accelerator values --
textMessage( tostring(centerX + (centerX * event.xGravity)), "naosei", 0.5, 12, {255, 255, 0} )
crate.x = centerX + (centerX * event.xGravity)
crate.y = centerY + (centerY * event.yGravity * -1)
-- sound beep if Shake'n
if event.isShake == true then
textMessage( "Shake!", "Top", 3, 52, {255, 255, 0} )
audio.play( shakeSound )
end
end
-----------------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
-----------------------------------------------------------------------------------------
-- Add runtime listeners
Runtime:addEventListener ("accelerometer", onAccelerate);
-- Add scene listeners
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched whenever before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-----------------------------------------------------------------------------------------
return scene
"level1.lua:161 attempt to index global 'crate' (a nil value)"
Because there is no crate variable in scope on line 161.
You do have a variable named crate inside of createScene but it's local, so it's only visible within that function. Line 161 is a different function (onAccelerate), there is no local crate variable in scope there, so Lua looks for a global (_G['crate']), gets back nil, and you try to index that. Hence the error.
Easiest fix: remove the keyword local from the crate on line 108, so you create a global. It's not pretty, but it should work.
I would avoid using global variables because of memory leak issues.
What I do is define the display object names in the root scope and then set them from within the createScene function. I think this helps lua to do garbage collection.
local background, crate
function scene:createScene( event )
local group = self.view
local background = display.newRect( 0, 0, screenW, screenH )
local crate = display.newImage('crate.png')
group:insert( background )
group:insert( crate )
end
Related
I created a new project in CoronaLabs Studio with Physics-Based Game starting options and everything loaded up as a beginner I don't get where should I put addEventListener() so I can make the box to be clickable or to be destroyed on click?
I tried a bunch of different ways to just place this line of code inside the script to make the box clickable virus:applyLinearImpulse( 0, -0.25, virus.x, virus.y )
Here is the level1.lua script.
In this case, I have
require("toast")
local composer = require( "composer" )
local scene = composer.newScene()
-- include Corona's "physics" library
local physics = require("physics")
--------------------------------------------
tapCount = 0
tapText = display.newText( tapCount, display.contentCenterX, 20, native.systemFont, 40 )
--------------------------------------------
local screenW, screenH, halfW = display.actualContentWidth, display.actualContentHeight, display.contentCenterX
function scene:create( event )
-- Called when the scene's view does not exist.
-- INSERT code here to initialize the scene e.g. add display objects to 'sceneGroup', add touch listeners, etc.
local sceneGroup = self.view
physics.start()
physics.pause()
local background = display.newImageRect("game-background.png", 1170, 658)
background.x = display.contentCenterX
background.y = display.contentCenterY
-- OFFSCREEN BOX, position it, and rotate slightly
local box = display.newImageRect( "box.png", 40, 40 )
box.x, box.y = 160, -100
box.rotation = 33
-- add physics
physics.addBody( box, { density=1.0, friction=0.3, bounce=0.2 } )
-- create a grass object and add physics (with custom shape)
local grass = display.newImageRect( "grass.png", screenW, 82 )
grass.anchorX = 0
grass.anchorY = 1
-- draw the grass at the very bottom of the screen
grass.x, grass.y = display.screenOriginX, display.actualContentHeight + display.screenOriginY
local grassShape = { -halfW,-34, halfW,-34, halfW,34, -halfW,34 }
physics.addBody( grass, "static", { friction=0.3, shape=grassShape } )
sceneGroup:insert( background )
sceneGroup:insert( grass )
sceneGroup:insert( box )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is still off-screen and is about to move on screen
elseif phase == "did" then
-- Called when the scene is now on-screen
physics.start()
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
-- Called when the scene is on-screen and is about to move off-screen
physics.stop()
elseif phase == "did" then
-- Called when the scene is now off-screen
end
end
function scene:destroy( event )
-- Called prior to the removal of scene's "view" (sceneGroup)
local sceneGroup = self.view
package.loaded[physics] = nil
physics = nil
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-----------------------------------------------------------------------------------------
return scene
If I have understood your question correctly,here's an example where you can click a box and destroy it.
function scene:create(event)
local function destroyMe(event)
display.remove(event.target)
event.target=nil
end
local box = display.newImageRect( "box.png", 40, 40 )
box.x, box.y = 160, 100
box.rotation = 33
-- add physics
physics.addBody( box, { density=1.0, friction=0.3, bounce=0.2 } )
box:addEventListener("tap",destroyMe)
end
If you're using touch event,then that event will have three phases.Hence be cautious.
The output I should get are the chick can jump right when i tap right and vice versa. But the two problems that I can't solve here are when I tap it will output in console like I tap twice. The second problem is the lanes are in array and keep on overlap everything, even the chick which is the player.
For this i include 2 lua files and 3 png.
This is my main.lua
display.setStatusBar( display.HiddenStatusBar )
local composer = require( "composer" )
print("entering gotoScene")
composer.gotoScene( "game2" )
print("out from gotoScene")
This is my game2.lua
---REQUIRES
local composer = require( "composer" )
local scene = composer.newScene()
local widget = require( "widget" )
local physics = require "physics"
physics.start()
physics.setGravity(0,0)
local lanes = {}
local laneID = 1
scroll = 2
---SIZE PHONE DECLARATION
local screenW = display.contentWidth --640
local screenH = display.contentHeight --1136
local halfX = display.contentWidth * 0.5 --half width 320
local halfY = display.contentHeight * 0.5 --half height 568
----------------------
----------------------
---WHEN TAP CHICK MOVE
local function tapListener( event )
local object = event.target
if object.name == "Right Side" then
print( object.name.." TAPPED!" )
if laneID < 3 then
laneID = laneID + 1;
transition.to(chick, {x=lanes[laneID].x,time=50})
print( "At lane "..laneID.." to the right")
end
return true
end
if object.name == "Left Side" then
print( object.name.." TAPPED!" )
if laneID > 1 then
laneID = laneID - 1;
transition.to(chick, {x=lanes[laneID].x,time=50})
print( "At lane "..laneID.." to the left")
end
return true
end
end
----------------------
---CREATE
-- Initialize the scene here.
-- Example: add display objects to "sceneGroup", add touch listeners, etc.
function scene:create( )
local group = self.view
---TAP BACKGROUND
RightSide = display.newRect(500,halfY, halfX+50, screenH + 100 )
RightSide.alpha = 0.1
RightSide.name = "Right Side"
LeftSide = display.newRect(140, halfY,halfX+50, screenH + 100)
LeftSide.alpha = 0.1
LeftSide.name = "Left Side"
----------------------
---TAP LABEL
rightLabel = display.newText({ text = "", x = 0, y = 0 , fontSize = 50 } )
rightLabel:setTextColor( 0 ) ; rightLabel.x = 500 ;rightLabel.y = halfY
leftLabel = display.newText({ text = "", x = 0, y = 0, fontSize = 50 } )
leftLabel:setTextColor( 0 ) ; leftLabel.x = 150 ; leftLabel.y = halfY
----------------------
---PATHWAY (BACKGROUND)
path1 = display.newImageRect("road.png",screenW,screenH)
path1.x = halfX
path1.y = halfY
path2 = display.newImageRect("road.png",screenW,screenH)
path2.x = halfX
path2.y = halfY - screenH
----------------------
---LANES
for i=1,3 do -- loop 3 times to create 3 lanes for our game
--myGroup=display.newGroup()
laneimg = display.newImageRect("lanesroad.png", 150, 1300)
lanes[i] = laneimg
lanes[i].x = (display.contentCenterX - 140*2) + (i*140)
lanes[i].y = display.contentCenterY
lanes[i].id = i
end
----------------------
---CHICK
chick = display.newImageRect("chick.png",100,100)
chick.anchorY = 1
chick.x = lanes[2].x
chick.y = 1000
physics.addBody(chick)
chick.bodyType = "dynamic"
----------------------
path1:toBack();
path2:toBack();
group:insert( RightSide )
group:insert( LeftSide )
group:insert( rightLabel )
group:insert( leftLabel )
group:insert( laneimg)
group:insert( chick )
end
----------------------
---BACKGROUND SCROLL
function pathScroll (self,event)
path1.y = path1.y + scroll
path2.y = path2.y + scroll
if path1.y == screenH * 1.5 then
path1.y = screenH * -.5
end
if path2.y == screenH * 1.5 then
path2.y = screenH * -.5
end
end
----------------------
---SHOW --that will show in scene
function scene:show (event)
---FOR ROAD TO SCROLL
path1.enterFrame = pathScroll
Runtime:addEventListener("enterFrame", pathScroll)
path2.enterFrame = pathScroll
Runtime:addEventListener("enterFrame", pathScroll)
----------------------
---WHEN TAP TO RIGHT
RightSide:addEventListener( "tap", tapListener )
rightLabel.text = "right"
----------------------
---WHEN TAP TO LEFT
LeftSide:addEventListener( "tap", tapListener )
leftLabel.text = "left"
----------------------
end
----------------------
---HIDE
function scene:hide (event)
end
----------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
return scene
enter image description here
enter image description here
The method scene:show is called twice. Once with event.phase paramater equal to will and second time with event.phase paramater equal to did. It also apply to scene.hide method. Code below check that.
At botom I put scene template from Corona documentation. It can be used as start point for new scene.
I commented out line with Runtime:addEventListener("enterFrame", pathScroll). You have two but one is enough.
More information you find with these links
Composer Library
Introducing the Composer API
Tap / Touch / Multitouch
Try (tested)
...
---SHOW --that will show in scene
function scene:show (event)
local phase = event.phase
if ( phase == 'will' ) then
elseif ( phase == 'did' ) then
---FOR ROAD TO SCROLL
path1.enterFrame = pathScroll
Runtime:addEventListener("enterFrame", pathScroll)
path2.enterFrame = pathScroll
--Runtime:addEventListener("enterFrame", pathScroll)
----------------------
---WHEN TAP TO RIGHT
RightSide:addEventListener( "tap", tapListener )
rightLabel.text = "right"
----------------------
---WHEN TAP TO LEFT
--LeftSide:addEventListener( "tap", tapListener )
leftLabel.text = "left"
----------------------
end
end
----------------------
...
Scene template
local composer = require( "composer" )
local scene = composer.newScene()
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
end
-- show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
end
end
-- hide()
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
end
end
-- destroy()
function scene:destroy( event )
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return scene
I'm developing clone version of Nintendo Tetris game using Corona SDK. There are two text objects on the top of my screen: one represents current level, another one represents current score. Every time I fill in line with blocks my program erases this line and add some scores and +1 level. The problem is that once I update my score and level variables and use myText.text to refresh my texts it doesn't erase old text and creates the new text that overlapping the old one.
My code is following:
1) I declare two local variables at the begging of my scene
local scoreText
local levelText
2) I have function that erases the line and updates texts
function eraseLines()
-- some code that erases lines
scores = scores + 10
scoreText.text = "Score:"..scores
level = level + 1
levelText.text = "Level:"..level
end
3) In scene:show(event) I create our texts
function scene:show( event )
-- some code
scoreText = display.newText("Score:"..scores, halfW*0.5, 20 )
levelText = display.newText("Level:".. level, halfW*1.5, 20 )
sceneGroup:insert( scoreText )
sceneGroup:insert( levelText )
scoreText:setFillColor( 0, 0, 0 )
levelText:setFillColor( 0, 0, 0 )
end
Please help me to find out why overlapping happens
At the moment you are adding twice score/level labels, 'cause the show event is called two times (phases) will and did. Add display objects when you are creating the scene.
-- create()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
scoreText = display.newText( "Score: 0", halfW * 0.5, 20 )
levelText = display.newText( "Level: 0", halfW * 1.5, 20 )
sceneGroup:insert( scoreText )
sceneGroup:insert( levelText )
scoreText:setFillColor( 0, 0, 0 )
levelText:setFillColor( 0, 0, 0 )
end
-- show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
scoreText.text = "Score: " .. score
levelText.text = "Level: " .. level
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
end
end
Here's a poorly constructed single script for displaying score
local scoreCounter = {}
local frameTime = 0
scoreCount = 0
finalScore = nil
local tempText = nil
local function update( event )
frameTime = frameTime + 1
--after every 7 frames score will increase
if(frameTime % 7 == 0) then
scoreCount = scoreCount + 1
tempText.text = scoreCount
frameTime = 0
end
end
-- here is a memory leak I guess
function scoreCounter.displayScore(xCoordinate, yCoordinate)
tempText = display.newText(scoreCount, xCoordinate, yCoordinate)
end
Runtime:addEventListener("enterFrame", update)
return scoreCounter
Usage:
local scoreCounter = require("pathtoluafile")
scoreCounter.displayScore(xCoordinate, yCoordinate)
why i cant see the cloud image and is says a nil value when i put x and y coordinate and lastly how could i make in go up and repaswn itself randomly?
local storyboard = require("storyboard")
local scene = storyboard.newScene()
local physics = require "physics"
physics.start( )
physics.setGravity(0, 0)
--physics.setDrawMode( "hybrid" )
local LEFT = 100
local CENTER = display.contentCenterX
local RIGHT = display.contentWidth - 100
the problem is around here. i tried to change imges and a variety of coding yet it failed
function scene:createScene(event)
local screenGroup = self.view
cloud = display.newImage( "cloud.jpeg")
cloud.x = 200
cloud.y = 900
back = display.newImage( "sky.png" )
back.x = display.contentWidth/2
back.y = display.contentHeight/2
screenGroup:insert(back)
end
local function handleSwipe( event )
if event.phase == "moved" then
local dX = event.x - event.xStart
print(event.x, event.xStart, dX)
if dX > 10 then
local spot = RIGHT
if event.target.x == LEFT then
spot = CENTER
end
transition.to( event.target, {time=350, x = spot } )
elseif dX < -10 then
local spot = LEFT
if event.target.x == RIGHT then
spot = CENTER
end
transition.to( event.target, {time=350, x = spot } )
end
end
return true
end
function scene:enterScene(event)
object = display.newImage( "diver.png", display.contentCenterX, display.contentHeight/1.7, 25 )
object:addEventListener( "touch", handleSwipe )
end
function scene:exitScene( event )
end
function scene:destroyScene( event )
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
return scene
anyone can help?
I think you don't have "cloud.jpeg" in a folder where main.lua is. Otherwise tell me which line bug is related to.
I am completely new to Corona SDK and I am just looking at the example projects just to see how things work. I am looking at the TAB example however I have a problem.
I have a page like so (this is page2)
local composer = require( "composer" )
local scene = composer.newScene()
function scene:create( event )
local sceneGroup = self.view
-- Called when the scene's view does not exist.
--
-- INSERT code here to initialize the scene
-- e.g. add display objects to 'sceneGroup', add touch listeners, etc.
-- create a white background to fill screen (things go in here like pictures etc)
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX = 0
bg.anchorY = 0
bg:setFillColor( 0 ) -- white
-- this will create the thing that you drag (the function is after)
local tracker = display.newRect( 568, 340, 50, 50 )
tracker:setFillColor( 1 )
-- all objects must be added to group (e.g. self.view)
sceneGroup:insert( bg )
sceneGroup:insert( tracker )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is still off screen and is about to move on screen
elseif phase == "did" then
-- Called when the scene is now on screen
--
-- INSERT code here to make the scene come alive
-- e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
-- Called when the scene is on screen and is about to move off screen
--
-- INSERT code here to pause the scene
-- e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == "did" then
-- Called when the scene is now off screen
end
end
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's "view" (sceneGroup)
--
-- INSERT code here to cleanup the scene
-- e.g. remove display objects, remove touch listeners, save state, etc.
end
function tracker:touch( event )
if event.phase == "began" then
self.markX = self.x --stores x location
self.markY = self.y --stores y location
elseif event.phase == "moved" then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y -- moves the object from things above
end
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
tracker:addEventListneer( "touch", tracker)
-----------------------------------------------------------------------------------------
return scene
Anyway to simplify things the changes I have done are:
local tracker = display.newRect( 568, 340, 50, 50 )
tracker:setFillColor( 1 )
This will create a new box which I am trying to make so you can drag it around the screen (I have used this function):
function tracker:touch( event )
if event.phase == "began" then
self.markX = self.x --stores x location
self.markY = self.y --stores y location
elseif event.phase == "moved" then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y -- moves the object from things above
end
end
So overall it creates a box and I am trying to add a function to it so that you can drag it around the screen. However it does not work and gives me an error saying that tracker on that start of the function line function tracker:touch( event ) is wrong? Any help, because I think that this is in the wrong place.
P.S I also have a tracker:addEventListneer( "touch", tracker) listener.
-Thanks
You are creating the local tracker as a local variable inside your scene:create function. This means this variable will only be available within the scope of said function.
You need to move the function tracker:touch(event) inside the scene:create function for the tracker to be reachable.
And you need to move the listener to the bottom of the scene:create function.
Never mind. I have fixed it. I should always check my spelling xD (I spelled the tracker:addEventListener( "touch", tracker) wrong). Such a noob mistake. Thanks for the help guys.