Drawing shapes on touch

I am new to codea, and I am trying to make a bingo game (just the sheets). The sheet is a sprite. I want a rectangle to be created wherever I touch. However, I keep getting an error. The code I used is below. It is probably something basic, but I don’t know what.

-------Main---------

-- Bingo

-- Use this function to perform your initial setup
function setup()
    print("Bingo")
    displayMode( FULLSCREEN )
    supportedOrientations(PORTRAIT_ANY)
    touchx()
    touchy()
end

function touched(touch)
    if touch.state ==  BEGAN
    then 
        touchx(touch.x)
        touchy(touch.y)
    end
end

function draw()
    background( 0 )
    sprite("Dropbox:Photo May 20, 2 25 52 PM", WIDTH/2, HEIGHT/2, 763)
    rectMode(CENTER)
    fill(255, 0, 0, 255)
    rect(touchx, touchy, 100, 100)
end


```

How do you embed code properly?

EDIT: thanks for the tips

three tildes before and after the code: ‘~~~’

@Saturn031000 Try this. Also, I added the three ~ to your code above to format it.

EDIT: code modified.


-------Main---------

-- Bingo

function setup()
    tab={}
    print("Bingo")
    displayMode( FULLSCREEN )
    supportedOrientations(PORTRAIT_ANY)
    touchx=0
    touchy=0
end

function touched(touch)
    if touch.state ==  BEGAN then 
        table.insert(tab,vec2(touch.x,touch.y))
    end
end

function draw()
    background( 0 )
    sprite("Dropbox:Photo May 20, 2 25 52 PM", WIDTH/2, HEIGHT/2, 763)
    rectMode(CENTER)
    fill(255, 0, 0, 255)
    for a,b in pairs(tab) do
        rect(b.x, b.y, 100, 100)
    end
end

@Saturn031000 I modified my code above to do what you requested. If you want to see code that creates a bingo card, I have code that does it. I’ll let you try on your own, but if you want to see the code, I’ll post it if you want.

@dave1707 Thanks for all the help.

@dave1707 that works, but the previous rectangle disappears after I touch a second time. Is there a way for it to stay, so that tapping the screen creates a rectangle, and tapping it again makes another one, and so forth? And thanks for the three ~ tip.