Simple Button query...

Hello,
I was working on a very simple little project, and wanted to create some buttons to select some options, but could not create anything meaningful. So I decided to create some rectangles, filling them up with colours, and tried to use their width and height stretch to determine if the rectangles are touched via ~if~ tests, but none of it worked…I’m trying from a long time to create simple buttons. Can anyone help me with a little example?
Thank you!

Maybe this will help

https://coolcodea.wordpress.com/2013/03/22/7-classes-in-codea/

https://coolcodea.wordpress.com/2013/03/23/8-classes-in-codea-2/

@CoderX Here’s a simple example.

function setup()
    str=""
end

function draw()
    background(40, 40, 50)
    fill(255)
    rect(200,200,100,50)
    text(str,WIDTH/2,HEIGHT/2)
end

function touched(t)
    if t.state==BEGAN then
        if t.x>200 and t.x<300 and t.y>200 and t.y<250 then
            str="touched"
        end
    end
    if t.state==ENDED then
        str=""
    end    
end

Thanks a lot dave1707, your example is splendid! Very compact and informative. Great button code, doesn’t even have classes. Thanx!

@CoderX If you want to have several buttons, then a button class would make it easy. The class could be just as simple as the code above.

Ok, I would want to figure that out for myself (When I know enough about ‘classes’ and ‘self’). Thank you!

@Ignatz, Thanks. Just saw your comment, reading the link articles.
I asked this question because I started working on a project recently, started as a project for creating and testing buttons, but it is much more right now…It is a possible simple game. I’ve been working on it for a week or more now and the present state looks little good. Can I send it to you, PLEASE, maybe you could improve the code, actually I don’t want to post it as a discussion right now. I need a little help with menus and options.

You can PM me a link to the code and I’ll have a look

Please explain exactly what you need help with