addEventListener "touch" not functioning

Hi,

I’m making my first steps in lua and corona and having a really embarrasing problem. I’m sure it’s my own stupidity that this is not working but I’m following this tutorial: http://www.youtube.com/watch?v=qEMGcy-mizM&list=UUyv9aW0TsL_7WAZqTPuKXqA&index=39&feature=plcp. And I just don’t seem to get the touch event working. I’ve added a print statement to the function that should be called on touch but that also doesn’t print in the console. Underneath I’ve pasted all my code so far, and I’m working on a windows 7 PC. If anyone could point me at what I’m forgetting or doing wrong that would be greatly appreciated. I’ve searched the forums but couldn’t find this problem there either :(. Hope you can help me, thanks in advance.

[code]
–place background image
local BackgroundImage = display.newImage(“wall.png”)

–place balloon image
local Balloon1 = display.newImage(“balloon.png”)
Balloon1.x = display.contentWidth / 2
–turn on Physics for Balloon
Physics.addBody(Balloon1, { bounce = 0.2 })

–plade floor image
local Floor = display.newImage(“floor.png”)
Floor.y = display.contentHeight - Floor.stageHeight / 2
–turn on Physics for Floor
Physics.addBody(Floor,“static”)

–hide status bar
display.SetStatusBar( display.HiddenStatusBar )

–add event to Balloon1
function MoveBalloon1(event)
print(“touched”)
Balloon1:applyLinearImpulse(0,-0.2,Balloon1.x,Balloon1.y)
end

–add event listener
Balloon1:addEventListener(“touch”,MoveBalloon1)
[/code] [import]uid: 134940 topic_id: 23508 reply_id: 323508[/import]

Are you getting any errors in the console? [import]uid: 19626 topic_id: 23508 reply_id: 94306[/import]

Hi sandhje

Try this code instead - you need to start the physics engine.

[lua]local physics = require( “physics” )
physics.start()

display.setStatusBar( display.HiddenStatusBar )

–place background image
local BackgroundImage = display.newImage(“wall.png”)

–place balloon image
local Balloon1 = display.newImage(“balloon.png”)
Balloon1.x = display.contentWidth / 2
–turn on Physics for Balloon
physics.addBody(Balloon1, { bounce = 0.2 })

–plade floor image
local Floor = display.newImage(“floor.png”)
Floor.y = display.contentHeight - Floor.stageHeight / 2
–turn on Physics for Floor
physics.addBody(Floor,“static”)

–add event to Balloon1
function MoveBalloon1(event)
print(“touched”)
Balloon1:applyLinearImpulse(0,-0.2,Balloon1.x,Balloon1.y)
end

–add event listener
Balloon1:addEventListener(“touch”,MoveBalloon1)[/lua] [import]uid: 122802 topic_id: 23508 reply_id: 94308[/import]

Hi,

Thanks for your quick responses :), @robmiracle: I get the following output in my console, @se460 I did start the physics engine, just overlooked it in my copy/paste of the last post… sorry :). I’ll paste the code where I start the physics below.

Copyright © 2009-2011 A n s c a , I n c .
Version: 2.0.0
Build: 2011.704
WARNING: object.stageHeight has been deprecated. Use object.contentHeight instea
d
Runtime error
…:\users\gebruiker\documents\corona\balloons\main.lua:23: attempt to c
all field ‘SetStatusBar’ (a nil value)
stack traceback:
[C]: in function ‘SetStatusBar’
…:\users\gebruiker\documents\corona\balloons\main.lua:23: in main chun
k
Runtime error: …:\users\gebruiker\documents\corona\balloons\main.lua:23: attem
pt to call field ‘SetStatusBar’ (a nil value)
stack traceback:
[C]: in function ‘SetStatusBar’
…:\users\gebruiker\documents\corona\balloons\main.lua:23: in main chun
k

--load physics  
local Physics = require("physics")  
Physics.start()  
--set some gravity  
Physics.setGravity(0,9.8)  

[import]uid: 134940 topic_id: 23508 reply_id: 94311[/import]

Oh, perhaps an import bit of extra information, when I touch the Balloon1 object I also don’t get any additional errors or messages in the console… :frowning: [import]uid: 134940 topic_id: 23508 reply_id: 94312[/import]

Hi sandhje

Try to change -

[lua]display.SetStatusBar( display.HiddenStatusBar )[/lua]

To:

[lua]display.setStatusBar( display.HiddenStatusBar )[/lua] [import]uid: 122802 topic_id: 23508 reply_id: 94314[/import]

small s in setStatusBar

display.setStatusBar( display.HiddenStatusBar ) [import]uid: 107098 topic_id: 23508 reply_id: 94315[/import]

se460 and Steve, thank you sooooo much :slight_smile: That was it. Off course my own stupidity, it was there in the console all along. Just overlooked it somehow, to focussed on the wrong thing I guess. Sorry for taking up your time and thanks for helping out. :slight_smile: [import]uid: 134940 topic_id: 23508 reply_id: 94316[/import]

It’s really important to always check your console log. The errors may not always be the most human readable, but it usually points you in the right direction and many times directly to the problem.
[import]uid: 19626 topic_id: 23508 reply_id: 94318[/import]

@sandhje - Please don’t beat yourself up so much. I’m sure everyone here was happy to help you and honestly we all make “simple” mistakes like this sometimes, especially early on.

Peach :slight_smile: [import]uid: 52491 topic_id: 23508 reply_id: 94425[/import]