Nooblet sliding menu help

I am trying to create a menu when you swipe right, a settings menu pops up. And when left it disappears. I have a function. That when you swipe right does function draw () menu () end()

When I swipe right it works fine.

When. I swipe left an infinite animation of boxes sliding to the left occur

function menu()

function menu()

        

if SideMenu == true then
    if menuX >= 0 then
        menuX = menuX
    else
        menuX = menuX + 15
    end
elseif SideMenu == false then
    if menuX <= 0 - WIDTH/4 then
        menuX = menuX
    else
        menuX = menuX - 15
    end
    
end

fill(255, 255, 255, 255)
        strokeWidth(2)
        stroke(0, 0, 0, 255)
        rect( menuX, menuY, WIDTH/4, HEIGHT)

end

Thanks! :3

@FearMe2142 Try something like this.

displayMode(FULLSCREEN)

function setup()
    state="normal"
end

function draw()
    background(0)
    fill(255)
    if state=="normal" then
        text("Normal screen",WIDTH/2,HEIGHT/2)
    end
    if state=="menu" then
        text("Menu screen",WIDTH/2,HEIGHT/2)
    end
end

function touched(t)
    if t.state==MOVING then
        if t.deltaY<0 then
            state="menu"
        elseif t.deltaY>0 then
            state="normal"
        end
    end
end

@FearMe2142 One suggestion, not just for you but also others, try to have a working example of the problem. Most people who want to help don’t want to have to try to figure out what code to add to to yours to get your code to work and then try to figure out what’s wrong. For me, I won’t even try.

@dave1707 okay, and thank you very much for all the help!!! What do you mean by a working example? the whole code?

I edited the one you gave me and I am still having issues with it moving to the left.

displayMode(FULLSCREEN)

function setup()
    state="normal"
    menuX = 0 - WIDTH/4
    menuY = 0
end

function draw()
    background(0)
    fill(255)
    if state=="normal" then
        text("Normal screen",WIDTH/2,HEIGHT/2)
        stroke(255, 0, 0, 255)
        strokeWidth(3)
        fill(0, 14, 255, 255)
        rect(menuX, menuY, WIDTH/4, HEIGHT/4)
        if menuX <=0 then
                menuX = menuX
            else
                menuX = menuX - 15
        end
    end
    if state=="menu" then
        text("Menu screen",WIDTH/2,HEIGHT/2)
        stroke(255, 0, 0, 255)
        strokeWidth(3)
        fill(0, 14, 255, 255)
        rect( menuX, menuY, WIDTH/4, HEIGHT)
        if menuX >= 0 then
                menuX = menuX
            else
                menuX = menuX + 15
        end
    end
end

function touched(t)
    if t.state==MOVING then
        if t.deltaY<0 then
            state="menu"
        elseif t.deltaY>0 then
            state="normal"
        end
    end
end

@dave1707 sorry it posted funny!

@dave1707 I got it to work and I learned a lot!!! Thank you a ton!!!

What I mean by a working example is all the code needed to run code to show what you’re having trouble with. In you’re first post, you just show the function menu. If I want to execute that code to see what you’re having trouble with, I have to add setup(), draw(), and I don’t know what else. I’m not saying to post all of your code, but just enough code to show the problem.

@FearMe2142 Glad you got it working. If you have other questions, there are a lot of people here to help.