how to make an event listener from a variable?

OK, so I am a complete noob with 2 weeks in this awesome SDK and I desperately need your help!

I am making a virtual pet app and I have a variable hunger set to default by 0. Than I’ll make it increase by 10 each xx minutes, when it reaches some figure the pet should change its status.

Well here’s my extremely newbie question :slight_smile: How is the listener supposed to look like?

For example

hunger = hunger + 50
if hunger = 50
then “hungry” = true
end
pet:addEventListener (?“hungry”?, getHungry)

function getHungry(event)
if event?..? then
pet:change…
end
end

eventName can’t be a boolean, right? how to bind the hunger value with the function?
I think I am missing something very simple… But its been 2 days, so no other way but ask for help…

Thanks!
[import]uid: 161390 topic_id: 29050 reply_id: 329050[/import]

No, the event name is a string, not a variable. You can’t assign a value, to a string like you are doing in:

then “hungry” = true

You also don’t need an event listener for this:

function getHungry()  
 pet:change...  
end  
  
hunger = hunger + 50  
if hunger \>= 50 then  
 getHungry()  
end  

if you really really want this to be an event listener, you can make it work that way, but it’s overkill when a simple function call will work.
[import]uid: 19626 topic_id: 29050 reply_id: 116898[/import]

oh… its funny how sometimes you get stuck on some wrong idea and just can’t look into another solution :slight_smile:
Huge thanks! Made my day! [import]uid: 161390 topic_id: 29050 reply_id: 116899[/import]