Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    button press goes onto next screen

    Help
    3
    4
    305
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      AlexTheNewCoder last edited by

      so I made a menu but I need a button press for it to work

      1 Reply Last reply Reply Quote 0
      • Dave
        Dave Fuze Team last edited by Dave

        Adding button controls is quite easy to begin with but quickly becomes complicated depending on what you want to do.

        To get the state of the controls, you must call the controls() function in your main loop. Usually this happens at the start. Here is a basic template:

        loop
            clear()
            c = controls(0)
        
            if c.a then
                // The A button is being pressed
            endif
        
            update()
        repeat
        

        However - this will check if the A button is being pressed, and will be true for as long as the button is held. This means if we were to do something inside that if statement, it will keep happening until we let go. This sometimes causes problems. Let's say you wanted to increase a number by 1 every time you press the A button:

        num = 0
        
        loop
            clear()
            c = controls(0)
        
            if c.a then
                num += 1
            endif
        
            update()
        repeat
        

        In the above program, it becomes almost impossible to actually increase the number by 1 - we would have to press the button for a single frame. This makes something like menu selection really hard to get working properly, so I recommend trying this method. It looks a little strange, but I did explain it in some detail in a Fuze Tutorial Video:

        Essentially you want to store the state of the controls on the previous frame. You can do this with a variable easily:

        c = controls(0)
        c_prev = c
        
        loop
            clear()
            c = controls(0)
        
            // This if statement means: "If A is pressed and it wasn't being pressed on the previous frame" - Basically, this will only happen once. If you hold A down, it can't pass through the IF anymore!
            if c.a and !c_prev.a then
                // A has been pressed - this will only happen once
            endif
        
            update()
            // Store the controls into the previous state variable before we start the next frame
            c_prev = c
        repeat
        

        Hope this helps you!

        1 Reply Last reply Reply Quote 2
        • Devieus
          Devieus last edited by

          To add to this, a great way of navigating a menu is through states, just variables you check for in every loop, drawing only what's necessary to get through the menus.

          1 Reply Last reply Reply Quote 0
          • Dave
            Dave Fuze Team last edited by

            @AlexTheNewCoder Although it might be a little advanced for the things you are used to at the moment, @Devieus makes a good point and it gave me the motivation to make a menu system program which uses states. You can find it at this post:

            https://fuzearena.com/forum/topic/1910/menu-system-program

            Don't worry if it's confusing at first. It might be a fun experience to figure it out and try to add to it! If you can get your head around it, this sort of technique is unbelivably useful in many applications. I actually also touch on it in the video I linked before - but the states in that program are for the sprite animation. In this system, the states are for the current page of the menu we're looking at. As you can see - it's a versatile technique!

            1 Reply Last reply Reply Quote 1
            • First post
              Last post