0

ok, I've been starring at this error message for better part of a day now.

I'm trying to make a simple eventlistner to run when someone touches a button. The problem is that hower ever I decided to name it it says it's nil and cannot be used.

I'm working on a scene with the name "scene", self.view named "sceneGroup". The rectangle I try to add a listner to is called "mMnew" and is in the group called "mMnewU".

I've tried to change the name between all of those. At first I hade problem with adding the eventlistener but solved it, problem was not the same sulution worked for the listners name.

Listner:

function scene.mMnewUeser:touch(event)  
        if(event.phase == "begun")then
            local test1 = display.newRect(100,150,40,40)
            test1:setFillColor(0,1,0)
            print("Touch found")
        end
    end

Added listner:

scene:addEventListener("touch", scene.mMnewUeser)

I'm still pretty green with this language and used to code in JavaC, php, html, sql and AS3.0. Sorry for my rockie problems!

UPDATE: After adding a few simple checkpoints check in the code, it would seam that it refuses to run the function scene:create(event) my scene does hwoerver get created by local composer = require("composer") local scene = composer.newScene()

Lukis
  • 652
  • 7
  • 20
JJ3c
  • 21
  • 3

1 Answers1

0

This

function scene.mMnewUeser:touch(event)

is not the correct syntax. You probably meant to have:

function scene:mMnewUeser(event)

which means you're adding new method with a name mMnewUeser to scene object. Then you can just use it as touch listener the way you did in the last line of code. See an explanation of the difference between . and : here.

Community
  • 1
  • 1
Melquiades
  • 8,496
  • 1
  • 31
  • 46
  • Well I tried as you said and removed the :touch part, but it stills says that the listner can't be nil: `addEventListner:listner cannot be nil: nil stack traceback: [C]: in function 'error' ?: in function 'gotoScene' main.lua:18: in main chunk` – JJ3c Nov 24 '15 at 15:48
  • What's on line 18 in main.lua? – Melquiades Nov 24 '15 at 16:44