Menu Buttons urgent!!

My game starts on my menu. 3 Buttons Play Store Settings. I have a function tab for each appropriate button. How do I make it go to say… My Play page I have made. or my Store etc. Do I take out the specific tabs and define each in the menu tab? I’m stumped with this. Although the answer is probably a few characters of code.

~Griffin

Here’s what i do; Im sure theres a more convenient way to do this, but this is how i do it in my game;

--set this for your button instance, changing objects to there appropriate terms in your app
button.action = function() menu-instance:menu-function() end


--inside the menu class
Menu:setup()
self.sub = nil
self.run = true
end

function Menu:draw()
if self.run == true then
--code here
else
self.sub()
end
end

function Menu:menu-function()
--important to use menu instance as code is ran through button class
menu-instance.sub = function() button-function:draw() end
self.run = false
end

Here’s a link to a simple menu example. Maybe this will help.

http://codea.io/talk/discussion/2647/menu/p1

How to post source so I can get help?

Go to your project, press and hold, click copy, then paste here

My menu is the one you made above. Just changed the names of buttons. In main I have

function setup()
     displayMode(FULLSCREEN)
     supportedOrientations(PORTRAIT)
end

function draw()
     --Nothing is here
end

Menu: @dave1707 code different name sprite as background added strokes and rectangles behind the words to make it look nice took away Select Option title and different colors

So what exactly isn’t working? Could you post your whole project?

EDIT: in case i wasn’t clear above, press and hold in project file viewer (main menu)

EDITED EDIT: Daves code appeares to me to be a self-running code (aka copy and paste into blank main file) and it doesn’t appear meant to work as a class

I have Daves code setup as a empty function tab, because it was easier for me to add what I needed. Ill post code in a few minutes

function setup()
    displayMode(FULLSCREEN)
    supportedOrientations(PORTRAIT)
end

function draw()
    menu()
end

function menu()
    sprite("Documents:Blue Sky 1", 400, 500, 800, 1100)
    
    w=WIDTH/2
    sh=HEIGHT-400
    ph=HEIGHT-600
    th=HEIGHT-800
     
    font("GillSans-Bold")
    fontSize(150)
    fill(255, 255, 255, 255)
    
    menuTitle1="..Private.."
    text(menuTitle1,w,HEIGHT-150)
    
    fill(255, 255, 255, 255)
    stroke(0, 0, 0, 255)
    strokeWidth(5)
    rect(200, 170, 375, 100) --Settings
    rect(200, 370, 375, 100) --Store
    rect(200, 570, 375, 100) --Play
 
    fill(84, 190, 231, 255)
    font("GillSans-Bold")
    fontSize(68)
    t1="Play"
    text(t1,w,sh)
    w1,h1=textSize(t1)
     
    t2="Store"
    text(t2,w,ph)
    w2,h2=textSize(t2)
    
    t3="Settings"
    text(t3,w,th)
    w3,h3=textSize(t3)
end

function touched(t)
    if t.state==BEGAN then
        if t.x>w-w1/2 and t.x<w+w1/2 and t.y>sh-h1/2 and t.y<sh+h1/2 then
            print("Play")
            sound("Game Sounds One:Menu Back")
        end
        if t.x>w-w2/2 and t.x<w+w2/2 and t.y>ph-h2/2 and t.y<ph+h2/2 then
            print("Store")
            sound("Game Sounds One:Menu Back")
        end        
        if t.x>w-w3/2 and t.x<w+w3/2 and t.y>th-h3/2 and t.y<th+h3/2 then
            print("Settings")
            sound("Game Sounds One:Menu Back")
        end  
    end  
end

Id reccomend making a button class and a menu class. Create all the buttons you need inside your menu class, then call your menu class through the draw function. Dave’s code is a good starting point, but could be simplified with a menu class. Here’s a sliding button class that i made

Button = class()

function Button:init( vertical, symbol, radius, trigger, defaulty, defaultx, action)
    self.vertical = vertical
    self.symbol = symbol
    self.size = radius
    self.trigger = trigger
    self.setpos = vec2 (defaultx, defaulty)
    self.position = vec2 (defaultx, defaulty)
    self.action = action
    self.color = color(0, 67, 255, 255)
    self.moved = false
end

function Button:draw() 
self.touchpos = vec2 (CurrentTouch.x, CurrentTouch.y)
    self.touchdist = self.touchpos:dist(self.position)
       fill(self.color)
    ellipse (self.position.x, self.position.y, self.size)
    fill(255, 255, 255, 255)
          font("GillSans-Light")
    fontSize (35)
     text (self.symbol, self.position.x, self.position.y) 


    
     if self.touch == true then
        if self.vertical == true then
            if self.touchdist < self.size/1.5 then
                if singler == nil then
                    singler = self.symbol
                else
                    if singler == self.symbol then
                if self.trigger > self.setpos.y then 
                    self.position.y =math.max (CurrentTouch.y, self.setpos.y)
                    self.position.y =math.min(self.trigger, self.position.y)
                else
                self.position.y =math.min (CurrentTouch.y, self.setpos.y)
                self.position.y= math.max (self.trigger, self.position.y)
                end
                end
                    end
                end
            else
            if self.touchdist < self.size/1.5 then
                if singler == nil then
                singler = self.symbol
                else
                if singler == self.symbol then
             if self.trigger > self.setpos.x then
                   self.position.x =math.max ( CurrentTouch.x, self.setpos.x)
                    self.position.x = math.min(self.trigger, self.position.x)
                    else
                    self.position.x = math.min (CurrentTouch.x, self.setpos.x)
                    self.position.x = math.max(self.trigger, self.position.x)
                    end
                end
                end
            end
        end
    end
    if self.touch == false then
        if self.position.y == self.trigger then
            self.action()
            elseif self.position.x == self.trigger then
            self.action()
        else
    self.position = self.setpos
            end
        end
end

function Button:touched(touch)
    if touch.state == BEGAN then
        self.touch = true
    elseif touch.state == ENDED then
        singler = nil   
        self.touch = false
        end
end

In your menu class’ setup, write this (changing to appropriate values)

button_name(true for up and down slider, false for sideways, "symbol for button", button radius, trigger position, starting y position, starting x position, function() action:action() end)

Or follow reef wings tutorial, it is quite good