Thanks for the reply again but i’ve got another error on line 185 "attempt to index local ‘leftBtn’ a nil vaule. Does this mean the game cant find the object? Trying to get around these problems can be very frustrating sorry to keep annoying you with these questions. If i give you my entire code for the level you can exaime where the problem lies:
[code]
–
– level1
– this is where you add external modules
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()
local movieclip = require(“movieclip”)
— Physics setup
local physics = require(“physics”)
physics.start()
physics.setGravity(0, 9.8)
–physics.setDrawMode(“hybrid”)
— declare your variables here they should all be Local Variables
— Display Variables ------
local background
local bottonFloor
local character
local leftBtn
local rightBtn
local jumpBtn
— Function Variables -----
---- Group Variables --------
---- Sound Variables --------
— ordinary variables ----+
local speedR = 4.5
local speedL = -4.5
– image tables
local standing = {}
local walkLeft = {}
local walkRight = {}
–
– NOTE:
– Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– BEGINNING OF YOUR IMPLEMENTATION
– Called when the scene’s view does not exist:
function scene:createScene( event )
local view = self.view
—variable declarations go here -------
– Declare your display groups in this section
–standing = {“images/characterStanding.png”}
rightBtn = {“images/characterWalkingA.png”,“images/characterWalkingB.png”,“characterWalkingC.png”}
walkleft = {“images/leftCharacterWalkingA.png”,“images/leftCharacterWalkingB.png”,“images/leftCharacterWalkingC”}
– Add all of your objects here that appear at the start of the screen and position them
background = display.newImage(“images/backgroundA.png”)
bottomFloor = display.newImage(“images/platform450x30.png”)
bottomFloor.y = display.contentHeight * 0.9
bottomFloor.x = display.contentWidth * 0.4
physics.addBody(bottomFloor,“static”)
character = movieclip.newAnim({“images/characterStanding.png”})
physics.addBody(character, “dymamic”)
leftBtn = display.newImage(“images/leftButton.png”)
leftBtn.x = display.contentWidth * 0.02
leftBtn.y = display.contentHeight * 0.9
leftBtn.pressed = false
rightBtn = display.newImage(“images/rightButton.png”)
rightBtn.x = display.contentWidth * 0.07
rightBtn.y = display.contentHeight * 0.9
rightBtn.pressed = false
jumpBtn = display.newImage(“images/jumpButton.png”)
jumpBtn.x = display.contentWidth * 0.045
jumpBtn.y = display.contentHeight * 0.85
— load your sound files here -------------
— add your objects to the view group e.g. view:insert(objectName)
view:insert(background)
view:insert(bottomFloor)
view:insert(character)
view:insert(leftBtn)
view:insert(rightBtn)
view:insert(jumpBtn)
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local view = self.view
end
— All Functions go in here
local gameLoop = function ()
if leftBtn.pressed == true then
character.x = character.x + speedL
end
if rightBtn.pressed == true then
character.x = character.x + speedR
end
end
local touchBtn = function (e)
local obj = event.target
if(e.phase == “began”) then
obj.pressed = true
end
if(e.phase == “ended”) then
obj.pressed = false
end
end
— Object listener declarations go here
leftBtn:addEventListener(“touch”,touchBtn)
rightBtn:addEventListener(“touch”,touchBtn)
Runtime:addEventListener(“enterFrame”,gameLoop)
jumpBtn:addEventListener(“touch”,jumpBtn)
— Timer Declarations go here
— Runtime listener “enterFrame” declarations go here
Runtime:addEventListener(“touch”,rightBtn)
Runtime:addEventListener(“touch”,leftBtn)
Runtime:addEventListener(“touch”,touchBtn)
– Called when scene is about to move offscreen:
function scene:exitScene( event )
— Remove Timers here
— Remove Runtime listener “enterFrame” declarations here
----- purge scene here ----------
storyboard.purgeScene(“level1”)
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
– this function is not normally used for simple games.
end
– END OF YOUR IMPLEMENTATION
– “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 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/code> [import]uid: 217352 topic_id: 35579 reply_id: 141535[/import]