Passing variable to eventListener

HI,

Trying to add a variable to a text field eventlistener.

Figured out that I need to use an anonymous event.

defaultField:addEventListener( “userInput”, function() testFlagsListener(myWord); end )

Problem is in the testFlagsListener I need to access the event and the passed parameter.

function testFlagsListener( event, inText )

 

When I try this, it seems the whole event gets ignored.

Essentially I’m trying to have user enter some text, and compare it with text I define. I don’t want to use global variables unless I have to.

Thoughts?

Try adding the event as an argument to your anonymous function:

defaultField:addEventListener( "userInput", function(e) testFlagsListener(e,myWord); end )

That event object is being sent to the anonymous function, you’ve just told the function to ignore it.

Excellent, thanks. That works. Not quite certain of the logic of why, but it’s good, thanks.

Try adding the event as an argument to your anonymous function:

defaultField:addEventListener( "userInput", function(e) testFlagsListener(e,myWord); end )

That event object is being sent to the anonymous function, you’ve just told the function to ignore it.

Excellent, thanks. That works. Not quite certain of the logic of why, but it’s good, thanks.