lose one's way in broad daylight

My question is very simple : how call touch function from class in main ? Like

function draw()
    
    br:draw()
    
end

but this dont work in touch func

There is snippet of my code :

Main class

function touched(t)

    br:touched()
end

Bricks class

function Bricks:touched(touch)
    -- Codea does not automatically call this method
    if touch.state == BEGAN then
    if self.vec:dist(vec2(CurrentTouch.x,CurrentTouch.y)) <= 20 then
        table.insert(cells,vec2(300,100))
        correcttap = correcttap + 1 
        if correcttap > 3 then
            correcttap = 0
            end
        end
        end
end

Try

Function touched(t)
    br:touched(t)
end

Well after reading your code I saw a few mistakes you’ve made…

The draw thing in the beginning is fine though.
When you tried to call the Bricks touch function from Main, you simply forgot to give the touch to the Bricks class touch function (codea also does not automatically do that)

I assume, you definded self.vec as a position on the screen in the init function of your Bricks class, so that’s fine. But later on in the same line you wrote vec2(CurrentTouch.x, CurrentTouch.y), which should be avoided when using the touched() function, because the argument (touch) parsed in the touched(…) function from your main class already contains every needed information about your specific touches on the screen.
You did not make this mistake one line above (when you wrote touch.state). Better do so over there too (meaning vec2(touch.x, touch.y), because CurrentTouch on,y contains information about your last touch on the display, which may differ from the one processed by the touched function at this position.
Also maybe check out touch.tapCount, it may help you further on :wink:

Thank you a lot for your response! About touch.x and touch.y : i know that) that line
was copied from draw function, there touch.x and touch.y dont work


    if touch.state == BEGAN then
    if self.vec:dist(vec2(CurrentTouch.x,CurrentTouch.y)) <= 20 then
        table.insert(cells,vec2(300,100))
        correcttap = correcttap + 1 
        if correcttap > 3 then
            correcttap = 0
            end
        end
        end

@TheMcSebi No, surprisingly, dont work. Codea didnt send error , but code dont work too

@TheMcSebi yeah, i know about tapCount, but this isn’t what i need

Guys, help me please

Try reading this

https://coolcodea.wordpress.com/2014/12/28/188-understanding-touch/

@ignatz thank you alot