Touch doesnt work

Hey i am learning corona sdk and i want to make a touch event but it gives me an error.

this is the code:

----------------------------------------------------------------------------------------- -- -- level1.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() -- include Corona's "physics" library local physics = require "physics" physics.start(); physics.pause() -------------------------------------------- -- forward declarations and other locals local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth\*0.5 local function doControlsTouch(event) local buttonPressed = event.targat if event.phase == "began" then if buttonPressed.id == "jump" then print("jump down") else print("left right") end elseif event.phase == "ended" then print("button is eneden") end end 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 -- create a grey rectangle as the backdrop local background = display.newRect( 0, 0, screenW, screenH ) background.anchorX = 0 background.anchorY = 0 background:setFillColor( .5 ) -- make a crate (off-screen), position it, and rotate slightly local crate = display.newImageRect( "crate.png", 90, 90 ) crate.x, crate.y = 160, -100 crate.rotation = 15 local hero = display.newRect(100,100,60,100) physics.addBody(hero,{density=1.0,friction = 0.3,bounce=0}) local controls = display.newRect(50,290,96,32) controls.id = "LeftRight" controls:addEventListener("touch",doControlsTouch) local btnJump = display.newCircle(400,290,16) btnJump:addEventListener("touch",doControlsTouch) btnJump.id = "jump" -- 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.anchorX = 0 grass.anchorY = 1 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 sceneGroup:insert( background ) sceneGroup:insert( grass) sceneGroup:insert(controls) sceneGroup:insert(btnJump) sceneGroup:insert( crate ) 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. 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 -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) 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) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. 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

it says that there is a problem with the buttonPressed(a nil value)

You have:

local buttonPressed = event.targat

you want:

local buttonPressed = event.target

You have:

local buttonPressed = event.targat

you want:

local buttonPressed = event.target