Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Is it possible to make an alert with buttons?

edited December 2016 in Questions Posts: 87

Using alert() Is it possible to make an alert with buttons?

Comments

  • dave1707dave1707 Mod
    Posts: 7,612

    It looks like it only has one button. You might have to make your own. Search the forum for examples.

  • dave1707dave1707 Mod
    Posts: 7,612

    @magicskillz Here's an example that I threw together. It can be done better, but I'll leave that up to you.

    function setup()
        ax=WIDTH/2-105
        ay=HEIGHT/2-80
        str=""
    end
    
    function draw()
        background(40, 40, 50)
        fill(255)
        text("Tap screen for alert",WIDTH/2,HEIGHT/2-50)
        if alertMsg then
            str=""
            showAlert()        
        end
        text(str,WIDTH/2,HEIGHT/2)
    end
    
    function touched(t)
        if t.state==BEGAN then
            if not alertMsg then
                alertMsg=true
                return
            end
            if t.x>ax+5 and t.x<ax+105 and t.y>ay+55 and t.y<ay+105 then
                str="Action1 was pressed."
                alertMsg=false
            end
            if t.x>ax+105 and t.x<ax+205 and t.y>ay+55 and t.y<ay+105 then
                str="Action2 was pressed."
                alertMsg=false
            end
            if t.x>ax+5 and t.x<ax+105 and t.y>ay+5 and t.y<ay+55 then
                str="Action3 was pressed."
                alertMsg=false
            end
            if t.x>ax+105 and t.x<ax+205 and t.y>ay+5 and t.y<ay+55 then
                str="Action4 was pressed."
                alertMsg=false
            end
        end
    end
    
    function showAlert()
        fill(255)
        rect(ax,ay,210,160)
        fill(0, 236, 255, 255)
        rect(ax+5,ay+110,200,40)
        fill(255,0,0)
        text("Select an action!",ax+105,ay+130)
        rect(ax+5,ay+55,100,50)
        rect(ax+105,ay+55,100,50)
        rect(ax+5,ay+5,100,50)
        rect(ax+105,ay+5,100,50)
        fill(255)
        text("Action1",ax+55,ay+80)
        text("Action2",ax+155,ay+80)
        text("Action3",ax+55,ay+30)
        text("Action4",ax+155,ay+30)
    end
    
Sign In or Register to comment.