Pre-declaring doesn't work?

The example code below doesn’t work.

If I move the function above where the event listener is added, it does work. I thought pre-declaring functions at the start of a lua file meant they could be used anywhere in the code?

Thanks

Tom

[lua]-- Hide status bar
display.setStatusBar(display.HiddenStatusBar);

– Define functions

local moveLeft;
local left = display.newImage(“control.png”);
left:addEventListener(“touch”, moveLeft);

function moveLeft(event)
– do something
end[/lua] [import]uid: 55068 topic_id: 16416 reply_id: 316416[/import]

Are you using the latest Daily Build?

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16416 reply_id: 61309[/import]

Hello

Yes, I just installed the latest version and tried again. I get:

“Copyright © 2009-2011 A n s c a , I n c .
Version: 2.0.0
Build: 2011.640
The file sandbox for this project is located at the following folder:
(/Users/tom/Library/Application Support/Corona Simulator/R2D2 Test-B2F0AD83A5E43743E27EE0496B918F03)
Runtime error
assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
…ers/tom/Documents/Corona Projects/R2D2 Test/main.lua:10: in main chunk
Runtime error: assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
…ers/tom/Documents/Corona Projects/R2D2 Test/main.lua:10: in main chunk”

Thanks [import]uid: 55068 topic_id: 16416 reply_id: 61318[/import]

Could someone please have a look into this?

Still can’t seem to work out what’s wrong.

Thanks
[import]uid: 55068 topic_id: 16416 reply_id: 61568[/import]

This is not quite how you would use this. (It’s also not necessary here.)

Just move line 10 to line 17.

If you’re interested in learning more about how to do this correctly I believe Ghosts VS Monsters is a good example :slight_smile:

Peach [import]uid: 52491 topic_id: 16416 reply_id: 61714[/import]