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:
1 2 3 4 5 6 7 8 9 | 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) |
enterFrame fires that listener EVERY frame. That would be 30 or 60 times a second.
What exactly are you trying to do here?
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?
you may use
Runtime:removeEventListener("enterFrame", show_thing)
when you want to stop triggering the event.
yeah,i know that) seems like im confusing myself)
so, are Runtime with many ifs and elseif's bad for memory?
thanks for answers
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
?:)
@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
1 2 3 | if tonumber(_G.somevar) == 1 then thing.isVisible = true end |
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...