touch problem

My function “Match” is not working with director,but it is working fine without director .Is there any other way to call a function when using Director?

[lua]for count = 1,4 do
x = x + 200
y = 20

for insideCount = 1,3 do
y = y + 200

wordcover[totalButtons] = display.newImage(“button.png”);
wordcover[totalButtons].x = x
wordcover[totalButtons].y = y
totalButtons = totalButtons + 1

temp = math.random(1,#words)
imgbtn[count] = display.newImage(words[temp] … “.png”);

imgbtn[count].x = x
imgbtn[count].y = y

imgbtn[count].myName = words[temp]
imgbtn[count].number = totalButtons

table.remove(words, temp)

imgbtn[count]:addEventListener( “touch”, imgbtn[count] )
imgbtn[count].touch = match

end
end
function match()
print (“Function is Working”)
end[/lua] [import]uid: 82446 topic_id: 17758 reply_id: 317758[/import]

could you try

imgbtn[count]:addEventListener( “touch”, match)
:slight_smile: [import]uid: 12482 topic_id: 17758 reply_id: 67718[/import]

Thanks for the reply.It worked but the problem now is that it is saying runtime error. Runtime error saying

[lua]Runtime error
attempt to index local ‘event’ (a nil value)
stack traceback:[/lua]

The code is below

[lua]function match(object, event)
if(event.phase == “began”) then
if(checkForMatch == false and secondSelect == 0) then
wordcover[object.number].isVisible = false;
lastButton = object
checkForMatch = true
elseif(checkForMatch == true) then
if(secondSelect == 0) then
wordcover[object.number].isVisible = false;
secondSelect = 1;
if(lastButton.myName ~= object.myName) then
timer.performWithDelay(1250, function()
checkForMatch = false;
secondSelect = 0;
wordcover[lastButton.number].isVisible = true;
wordcover[object.number].isVisible = true;
end, 1)
elseif(lastButton.myName == object.myName) then
timer.performWithDelay(1250, function()
checkForMatch = false;
secondSelect = 0;
lastButton:removeSelf();
object:removeSelf();
wordcover[lastButton.number]:removeSelf();
wordcover[object.number]:removeSelf();
end, 1)
end
end
end
end
end[/lua] [import]uid: 82446 topic_id: 17758 reply_id: 67736[/import]

Your function match() is expecting 2 params to be passed into it, object and event. But I think only one is actually being passed in and that is event. Since you have object listed first, it gets set to the event value that is passed in and event doesn’t get set to anything.

I think you have to change this so that event is the only param the function is expecting. Then look at event.target, event.id oe event.name , one of them may give you the object.number. [import]uid: 67839 topic_id: 17758 reply_id: 67816[/import]

when you put this line

imgbtn[count]:addEventListener( “touch”, match)

your function must be like

function myff(event)

end

and you can get target by event.target
:slight_smile: [import]uid: 12482 topic_id: 17758 reply_id: 67859[/import]