About touched(t) for button in table

Hi sorry to trouble all dear.

I hv a seriers button , same as button class iin cargobot, i put them in a table ,wchich is button24

I init each button and insert them into button by order. In. For…in ipair …
Also i sprite the button img for each button in draw. Until now ,all can work well.

Also there is a single button named buttonA,not belong to the table above .

In bottom, function touched(t)
I pass t to buttonA by: buttonA:touched(t)
In draw i make its function: buttonA:onBegan =function(buttonA,t)
This button can work well .

Also in touched(t)
I do :
For i,v in ipair(button24)
button24[i]:touched(t) end. ( I don’t know the problem is fm here or the following…)

In draw, i do:
For i,v in ipair(button24)
button24[i].onBegan = function(button24[i],t) ???
sound(asoundhere in pack) end

Red error always show the line number on the line with ???

Where am i wrong? Or cannot pass t to the button in table ? Or how to pass in ???

Thanks a lot.

@totorofat The variable t is only usable in the function touched the way it’s being used. The variable t that you’re using in draw isn’t defined so that’s probably why you’re getting an error. That’s what I see from the amount of code you’re showing.

thanks dave… finially I solved it in midnight.
in this line : button24[i].onBegan = function(button24[i],t) ???

as I suddenly found I wrote button24[i]:onBegan
it is : , not a dot.

But I wrote the dot in this post. so in the post it is right.

the small dot stopped my working since 4pm to midnight, the crazy dot.

I think , if the error in red shows only a number in red tag , it will means the format of this line has problem, such as : to ., missing [ or ], missing or exceeded end, missing something in format , right ?

I have a little PGM here, and i want to change the touch function from touch.screen to touch.button, please help anyone. Once i figure this out i will be able to apply it all of my PGMs… Below is a sample in which i have already drawn the button, i just need to change screen.touch to button.touch…

-- Shuffle PGM

function setup()
   s={" ??"," ??"," ??"," ??"}
   v={" 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10"," J"," Q"," K"," A"}
   for z=0,51 do
function draw()
   background(28, 32, 139, 255)
   text("Tap Button to shuffle",WIDTH/2,HEIGHT-50)
   for z=0,51 do
    stroke(255, 0, 8, 255)
    ellipse(100, 400,150)
    fill(0, 0, 0, 255)
    text("Shuffle", 100, 400)

function shuffle()
   for q=1,100 do
function touched(t)
   if t.state==BEGAN then
     sound("Game Sounds One:Bell 2")

@kendog400 Since you already have the button drawn, all you need to do in the touched function (BEGAN) is to check if the t.x and t.y values are within the circle. Instead of writing code to check a circle, you can imagine a square that covers some of the circle and check if t.x and t.y are within the square.

Could you hit me with a quick example, i look on the fourm, i see a lot of posts, I’m still having trouble comprehending, i’ll be ok once i get my roll on…
Thanks in advanced !..ps : (this is my first button)

@kendog400 Here’s the touched function. I’m thinking of a square inside the circle and using the size of the square for the Button.

PS. You can use a calculation for a circle to use the full size of the circle, but using a square inside the circle is good enough for now.

function touched(t)
    if t.state==BEGAN then
        if t.x>45 and t.x<155 and t.y>345 and t.y<455 then
            sound("Game Sounds One:Bell 2")

Got it now, thank you again !