How do you make buttons?

I was wondering how to make a scene with a button. My friend sent me a button example and It was sorta Advanced so it was hard to remember how to make one. And also wen ever I click on the button it would take me to another scene but wen I go to a 3rd scene and I tap were button two was it takes me back to scene two. So can someone show me how to create a esey button that sticks with the it’s button appearance. ( if you don’t understand what I mean just ask )

@AveryD See the discussion ‘Simple Button query’ about 18 discussions down. If you do a forum search, I’m sure you’ll find a lot of examples.

@dave1707 thanks

@dave1707 I didn’t find it

function setup()
    pos=1
end

function draw()
    background(0)
    fill(255)
    rect(200,200,50,180)  
    fill(255,0,0)
    rect(200,200+pos*60,50,60)
end

function touched(t)   
    if t.state==BEGAN then
        if t.x>200 and t.x<250 and t.y>200 and t.y<380 then
            if t.y>320 then
                pos=2
            elseif t.y>260 then
                pos=1
            else
                pos=0
            end
        end
    end
end

@erickyamato not what I’m looking for…

@AveryD this is just an example ( @dave1707 's example)

Try to search no the right top corner

@erickyamato @dave1707 what my friend sent me went somthing like this

Scene1 = 0

Scene2 = 1

state = Scene1

state = Scene2

Scene1 = Button(100,100,"Button"function()state-Scene1 end)
Scene2 = Button(200,200,"Button"function()state-Scene2 end)

function setup()
    func=menu
    mb1=button(WIDTH/2,HEIGHT-200,100,50,"EASY")
    mb2=button(WIDTH/2,HEIGHT-400,100,50,"NORMAL")
    mb3=button(WIDTH/2,HEIGHT-600,100,50,"HARD")
    eb1=button(WIDTH/2,HEIGHT-200,100,50,"Menu")
    nb1=button(WIDTH/2,HEIGHT-300,100,50,"Menu")
    hb1=button(WIDTH/2,HEIGHT-400,100,50,"Menu")
end

function draw()
    background(40, 40, 50)
    func()       
end

function touched(t)
    if t.state==BEGAN then
        if func==menu and mb1:touched(t)=="EASY" then
            func=easy
        elseif func==menu and mb2:touched(t)=="NORMAL" then
            func=normal
        elseif func==menu and mb3:touched(t)=="HARD" then
            func=hard
        elseif func==easy and eb1:touched(t)=="Menu" then
            func=menu
        elseif func==normal and nb1:touched(t)=="Menu" then
            func=menu
        elseif func==hard and hb1:touched(t)=="Menu" then
            func=menu
        end 
    end  
end

function menu()
    background(167, 125, 96, 255)
    mb1:draw()
    mb2:draw()
    mb3:draw()
end

function easy()
    background(0,0,255)
    fill(255)
    text("EASY Screen",WIDTH/2,HEIGHT/2)
    eb1:draw()
end

function normal()
    background(0,0,255)
    fill(255)
    text("NORMAL Screen",WIDTH/2,HEIGHT/2)
    nb1:draw()
end

function hard()
    background(0,0,255)
    fill(255)
    text("HARD Screen",WIDTH/2,HEIGHT/2)
    hb1:draw()
end

button = class()

function button:init(x,y,w,h,txt)
    self.x=x
    self.y=y
    self.w=w
    self.h=h
    self.txt=txt
end

function button:draw()
    rectMode(CENTER)
    fill(255)
    rect(self.x,self.y,self.w,self.h)
    fill(255,0,0)
    text(self.txt,self.x,self.y)
end

function button:touched(t)
    if t.state==BEGAN then
        if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and
            t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
                return self.txt
        end
    end
end

@erickyamato thanks I’ll try it out

@AveryD Try doing a forum search on menu.

@AveryD, we are here on forum to help you, not to write for you!

Maybe this will help you

function setup()
    startmenu=true
    menu=0
end
function draw()
    background(100)
    fontSize(50)
    if startmenu==true then
        text("Button 1",WIDTH/2,600)
        text("Button 2",WIDTH/2,400)
        text("Button 3",WIDTH/2,200)
    end
    if menu>0 then
        text("Menu "..menu,WIDTH/2,383)
    end
end
function touched(t)
    if t.x>412 and t.x<612 and t.y>550 and t.y<650 then
        startmenu=false
        menu=1
    end
    if t.x>412 and t.x<612 and t.y>350 and t.y<450 then
        startmenu=false
        menu=2
    end
    if t.x>412 and t.x<612 and t.y>150 and t.y<250 then
        startmenu=false
        menu=3
    end
end

Personally I find this the easiest way to make simple menus.
@erickyamato I know what you mean but we’re just giving him examples so he can learn from them.

@wildcat_JK you’re right!

But, it was that @dave1707 said, before ask, just search on menu

@erickyamato sorry, I thought you meant something else besides @dave1707’s statement haha

@erickyamato oh I’m not trying to make people write code for me. I just needed a simple example. I mean I all ready sorta know how a button worka

@erickyamato works*