How to fire Runtime listener once?

Hello again, seems like a need a lot of help today)

i’d really like to know, is there any way to stop Runtime listener from firing forever?
say i have this:
[lua]local function show_thing()
if tonumber(_G.somevar) == 1 then
thing.isVisible = true
print(thing.isVisible)
end
return true
end

Runtime:addEventListener(“enterFrame”, show_thing)[/lua]
it will work fine, but also it will make my terminal stack all those “true” and so on without stopping
i tried to return true, but it doesnt seem to work…

is there any way to stop this? i dont know if this is bad for device memory, so i concerned [import]uid: 16142 topic_id: 14874 reply_id: 314874[/import]

enterFrame fires that listener EVERY frame. That would be 30 or 60 times a second.

What exactly are you trying to do here? [import]uid: 8872 topic_id: 14874 reply_id: 54926[/import]

nothing,just set .isVisible = true or false upon changing variables

i just want to know if i want to do this kind of thing, maybe its bad for memory
also, if i make a function thats working on touch and then attach listener for it in a runtime functions - its fires many times, instead of one
is it normal? [import]uid: 16142 topic_id: 14874 reply_id: 54950[/import]

you may use
[lua]Runtime:removeEventListener(“enterFrame”, show_thing)[/lua]

when you want to stop triggering the event. [import]uid: 71210 topic_id: 14874 reply_id: 54976[/import]

yeah,i know that) seems like im confusing myself)

so, are Runtime with many ifs and elseif’s bad for memory?

thanks for answers [import]uid: 16142 topic_id: 14874 reply_id: 54981[/import]

if you want it to fire only once, why do you not use a timer.performWithDelay()

that will fire once and you do not have to add and then remove runtime listeners.

cheers

?:slight_smile: [import]uid: 3826 topic_id: 14874 reply_id: 54996[/import]

@darkconsoles you wan’t to make something visible when the variables value is 1 right ? why can’t you make it visible where you are setting the value of that variable ? or is the variable
_G.somevar coming from some other file ? in that case why you need to do it inside an enter frame ? you can just put

[lua]if tonumber(_G.somevar) == 1 then
thing.isVisible = true
end[/lua]
[import]uid: 71210 topic_id: 14874 reply_id: 55003[/import]

just “if” statement did not work, because i need to check this vars in gui module

yeah, i can call function when things changes, but with runtime it easier… [import]uid: 16142 topic_id: 14874 reply_id: 55074[/import]