UI Button problem...

Having an issue I can't resolve.

I have a function we will call MakeButtons

MakeButtons creates some buttons using UI Library and puts them in a table we will call buttonTable that is called at the top of the app and is Global

Each UIButton calls another function doWhenPressed.

While within MakeButtons everything works as expected. buttonTable[x].isVisible works for example.

doWhenPressed takes the event.id (which is verified to have same value as x). ie buttonTable[x] =buttonTable[event.id]

However buttonTable[event.id].isVisible does not work. In fact buttonTable[x] when x is forced also does not work.

Any clues anyone?

I cleaned up the code so I could post an example
At the top of the program:

1
 buttonTable={}

I'm no expert in Lua, but I believe at least part of the problem is in doWhenPressed(event).

The event.id is not the same as the id you set in the button above. What you want, I think, is something like:

1
2
3
4
5
6
7
8
function doWhenPressed(event)
        local t = event.target
        if(t.id == canToPop) then
                winscenario = true;
        else
                buttonTable[t.id].isVisible=false;
        end
end

If I print(event.id), I have it correct index. Verified the type is number as well.

Solved: Bug maybe???

The uiButtons get called multiple times on a single button press. Maybe I am just not following the code well enough. I made a checker to ensure the button only gets pressed once and now everything is fine.

Remember, multiple events get generated each time a button is tapped.

For buttons, I always check that the event type (or "phase") is "ended", which means that the user lifted a finger from the button. But there are others, like "began" and "moved" as well. If you look at the sample code, you often see something like

1
2
3
function dosomethingwithbutton(event)
        local phase = event.phase
        if "ended" == phase then
views:1363 update:2011/10/6 9:28:12
corona forums © 2003-2011