Drawing a box to keep with you're score in it.

I have the code to keep a current score while playing a game, but how do you draw a simple box, perhaps with or without a texture, like a board, with the “score: x” (“x” being your current score, don’t worry about all that.)
Here’s the code for the scoring…

    fill(255,255,255,255)
    textMode(CENTER)
    textAlign(CENTER)
    fontSize(20)
    font("Zapfino")
    text("Score: "..score,WIDTH/1.30,HEIGHT-20)
end

I would like the box to be centralized around the “score” text, and where it is positioned.
And I’m sorry for coming off like I don’t have a clue, but I’m still warming up to the draw functions…
Sorry

I believe textMode and textAlign is center by default, so no need for that code.

In setup() do rectMode(CENTER), then you can place it at same coordinates at the text. Draw it before the text so it is behind it.

In draw if you wanted a simple rectangle behind the score, you just use rect(x,y,w,h).

If you have an image you want to use for the background of the score, use sprite(object,x,y,w,h)

But it’s only default for the first time the main draw loop is run. Then it’s whatever the current setting is

You can use w, h = textSize("Sample Text") to get the size of text (make sure to call it AFTER all the font()s and fontSize()s). Then you could try use textMode(CORNER), and have the X and Y be WIDTH - w, HEIGHT - h (w, h being text size)

Edit: here you go:

    fill(255,255,255,255)
    textMode(CORNER)
    textAlign(RIGHT)
    fontSize(20)
    font("Zapfino")
    local w, h = textSize("Score: "..score)
    text("Score: "..score,WIDTH-w,HEIGHT-h)
end


function setup()
    rectMode(CENTER)
    score=123456
end

function draw()
    background(40, 40, 50)
    
    -- draw rect
    stroke(255, 9, 0, 255)
    strokeWidth(4)
    fill(0, 8, 255, 255)
    rect(WIDTH-130,HEIGHT-30,250,50)
    
    -- draw score
    fontSize(20)
    font("Zapfino")
    fill(255,255,255,255)
    text("Score: "..score,WIDTH-130,HEIGHT-35)
end