Here’s my problem. And I might be going about this the wrong way, but I’m trying to enable/disable buttons.
To simplify things, I have 4 buttons. When one button is activated, it moves to the center of the screen, then needs to deactivate all other buttons, so only that button can be pressed and moved back to the original position. Now, I have this semi working, but what is happening, is after I enable the button, and that button should then disable the other buttons again, it doesn’t work. (To disable the button, i’m removing the event listener)
Here’s the basic code that you need to see.
–Cross, Trust, God, Man are all buttons. dragging is the function that brings the button to the center.-
local function DisableAll (event)
Cross:removeEventListener(“touch”, dragging)
Trust:removeEventListener(“touch”, dragging)
God:removeEventListener(“touch”, dragging2)
Man:removeEventListener(“touch”, dragging2)
end
local function EnableAll (event)
Cross:addEventListener(“touch”, dragging)
Trust:addEventListener(“touch”, dragging)
God:addEventListener(“touch”, dragging2)
Man:addEventListener(“touch”, dragging2)
end
–Here’s the function for the Cross button. All others are pretty much the same. Names corresponding to themselves of course.–
local function snapCross (event)
–go back to original state
if Cross.x < 130 and CrossIn == true then
EnableAll()
transition.to(Cross, {time=750, x=-156, delay=0, alpha=.6,transition=easing.outExpo})
timer.performWithDelay(750, CrossInFalse)
end
–go to center and CrossInTrue
if Cross.x > -110 and CrossIn == false then
DisableAll()
transition.to(Cross, {time=750, x=175, delay=0, alpha=1, transition=easing.outExpo, onComplete = Cross:addEventListener(“touch”, dragging)})
timer.performWithDelay(750, CrossInTrue)
end
–limit x from going past center
if Cross.x > 176 and CrossIn == true then
transition.to(Cross, {time=10, x=175, delay=0, alpha=1, transition=easing.outExpo})
end
end
–
So in Theory, every time snapCross if fired, it should disable all the buttons. And it does the first time, but after it gets Enabled again, then snapCross is fired again, it doesn’t work. Is there something that happens where functions only fire one time, then they are done? Is it perhaps an add/remove event listener problem? I’ve been wrestling with this for a couple days. It makes sense to me that it should work. Any help would be super appreciated. [import]uid: 11144 topic_id: 6230 reply_id: 306230[/import]