Navigation

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

    Left-Right Joycon buttons dont work

    Help
    7
    23
    987
    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.
    • K
      kendog400 F last edited by

      Can anyone tell me why my left-right joycon butttons dont work ? I have a PGM with 5 buttons and 1 hilite overlay button, but I cant get the hilite button to move....

      clear ( )
      // 1st red button location along the x axis
      q = 80
      // the hilite button
      r = 160
      oldL = 0
      oldR = 0
      //...................................................................

      // Main loop

      for i = 0 to 5 loop
      box (q, 550, 160, 70, red, false)
      q += 236
      sleep (1)
      repeat

      // the hilite button
      box_2 = createbox (r, 583, 160, 40)
      setVetexColor (box_2, 0, {1, 1, 1, 0.1} )

      // Go to selection Fx
      selection ( )
      sleep (1)
      //.........................................................................

      function selection ( )

      c = controls (0)

      if c.left and !oldL then
      r = (r - 236)
      endif

      if c.right and !oldR then
      r = (r - 236)
      endif

      oldL = c.left
      oldR = c.right
      update ( )
      return void
      //...........................................................................

      1 Reply Last reply Reply Quote 0
      • DomDom
        DomDom F last edited by

        That code does not loop . So it only executes once before exiting.
        You also need to use a drawShape() command if you make a box using createbox() rather than just box()

        1 Reply Last reply Reply Quote 0
        • DomDom
          DomDom F last edited by

          Try starting a loop just before you create the box and moving update() out of the selection function and putting it at the end of the main loop

          1 Reply Last reply Reply Quote 0
          • DomDom
            DomDom F last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • DomDom
              DomDom F last edited by pianofire

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • DomDom
                DomDom F last edited by DomDom

                This post is deleted!
                1 Reply Last reply Reply Quote 1
                • pianofire
                  pianofire Fuze Team last edited by

                  I will rotate that for you!

                  1 Reply Last reply Reply Quote 2
                  • K
                    kendog400 F last edited by Dave

                    Everything works fine, but 1 question : When I put in sound/audio, now the PGM loops, where as before it would stop and show the buttons..Is there any reason why it went into a constant Loopinstead of just stoping ? Take a peek to see if I did something wrong....

                    // Set-up section
                    q = 80      // the 1st red box location
                    r = 160    //  the 1st selection box location
                    oldL = 0
                    oldR = 0
                    Box2 = create box (r, 583, 160, 40)
                    //...................................................
                    
                    // Main Loop
                    
                    loop 
                       for i = 0 to 5 loop
                         sndEff = loadAudio ("Gijs De Mik / Fx_Bleeps_01")     // sound of red button popping up
                         playAudio (0, sndEff, .5, .5, 2, 1)
                         box (q, 550, 160, 70, {1,0, 0, 1} )
                         q += 236
                         sleep (1)
                       repeat
                    
                         q = 80
                         deleteShape (Box2)
                         Box2 = createBox (r, 583, 160, 40)
                         sndEff = loadAudio ("Wild forts / Fx_Item_Get_03")     // sound of selection button popping up
                         playAudio (0, sndEff, 3, .5, 2, 1)
                         drawShape (Box2)
                         setVertexColor (Box2, 0, {1, 1, 1, 0.1} )
                         sleep (1)
                         selection ( )                        // go to selection Fx
                         update ( )
                    repeat
                    
                    //......................................................................
                    
                    function selection ( )
                        c = controls ( )
                          if c.left and !oldL then 
                            r = (r - 236)
                          endif
                    
                          if c.right and !oldR then 
                            r = (r + 236)
                          endif
                    
                    oldL = c.left
                    oldR = c.right
                    
                    return void
                    
                    //....End PGM
                    
                    M 1 Reply Last reply Reply Quote 1
                    • M
                      Maxwello F @kendog400 last edited by

                      @kendog400 what does the last argument in the play audio do?

                      SteveZX81 1 Reply Last reply Reply Quote 0
                      • SteveZX81
                        SteveZX81 F @Maxwello last edited by

                        @Maxwello said in Left-Right Joycon buttons dont work:

                        @kendog400 what does the last argument in the play audio do?

                        loops number of times to repeat (-1 is forever)

                        waldron 1 Reply Last reply Reply Quote 0
                        • waldron
                          waldron F last edited by waldron

                          The last argument in play audio is numbers of loop so 0 will play once, and I think its better to load audio out of the loop?? .... Best I can do to help

                          1 Reply Last reply Reply Quote 0
                          • waldron
                            waldron F @SteveZX81 last edited by

                            @SteveZX81 just beat me to it lol

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

                              @kendog400 The problem is that your main loop

                              loop
                                clear()  // clear frame buffer
                                         // draw stuff to frame buffer
                                update() // draw frame buffer to the screen
                              repeat
                              

                              will try to run at 60fps (repeat every 1/60th of a seconds) and without a condition will loop forever (or until the program is interrupted)

                              However you have sleep statements inside of it which stop the program flow for the specified interval causing it to become unresponsive

                              Your program draws 5 boxes and beeps at 1 second intervals. It then makes another sound and draws another box and then the whole thing just repeats

                              What I think you intended was for the first bit to only run once in which case you need a boolean value (or flag) to control this

                              q = 80
                              r = 160
                              oldL = 0
                              oldR = 0
                              Box2 =createBox( r, 583, 160, 40 )
                              sndEff1 = loadAudio("Gijs De Mik/FX_Bleeps_01")
                              sndEff2 = loadAudio("Wild Forts/FX_Item_Get_03")
                              
                              runOnce = true
                              oldc = controls(0)
                              loop
                                clear()
                                c = controls(0)
                                for i = 0 to 5 loop
                                  box(q, 550, 160, 70, { 1, 0, 0, 1 }, 1)
                                  if runOnce then
                                    playAudio(0, sndEff1, .5, .5, 2, 1)
                                    update()
                                    sleep(1)
                                  endif
                                  q += 236
                                repeat
                                runOnce = false
                                q = 80
                                if c.a and !oldc.a then
                                  r = r + 236
                                  setShapeLocation(Box2, r, 583)
                                  playAudio(0, sndEff2, 3, .5, 2, 1)
                                endif
                                drawShape(Box2)
                                setVertexColor( Box2, 0, {1,1,1, 0.1})
                                oldc = c
                                update()
                              repeat
                              

                              A couple of other points. You don't need to keep loading the audio clips in the loop you can just do this once at the top. Also the box only needs to be created once and can then be relocated.

                              I hope that this makes sense!

                              waldron 1 Reply Last reply Reply Quote 1
                              • waldron
                                waldron F @pianofire last edited by

                                @pianofire really helpful I put code where it is because other people put it there but now I understand why.

                                1 Reply Last reply Reply Quote 2
                                • K
                                  kendog400 F last edited by Martin

                                  I did get the buttons to work, but as soon as I plug it into a PGM, then it stops working. I think I'm doing something wrong or I'm leaving something out like a boolean flag or a drawShape ( )......Does anyone see something wrong ?.......I print out 5 cards to the screen, then bamb ! , my buttons dont work anymore.....I needed the buttons to select a card (or cards) to discard...................

                                  // Set-up
                                  clear (darkgreen)
                                  sleep (0.1)
                                  drawText (150, 250, 40, white, "Shuffling !")
                                  deck = loadImage ("Kenney / board games")           // load sprite sheet
                                  Suits = [ "clubs", "diamonds", "hearts", "spades"]
                                  x = 50
                                  y = 200
                                  q = 80
                                  r = 160
                                  oldL = 0
                                  oldR = 0
                                  Box2 = createBox (r, 583, 160, 40)
                                  sndeff1 loadAudio ("Wild Forts / FX - Card Shuffle")
                                  sndeff2 loadAudio ("Wild Forts / FX - Card deal")
                                  sndeff3 loadAudio ("Giji De Mik / FX - Bleep_01")
                                  sndeff4 loadAudio ("Giji De Mik / FX - Item Get_03")
                                  array Cards [52]
                                  getPack ( )
                                  shufflePack ( )
                                  //...............................................................................
                                  
                                  // Main Loop
                                  playingSound = true
                                  playAudio (0,sndeff1, 9, .5, .5, .5, 1)
                                  sleep (4)
                                  clear (darkGreen)
                                  sleep (.3)
                                  
                                      for i = 0 to 5 loop
                                        card = cards [ i ]
                                        size = getSpriteSize (Card)
                                        setSpriteLocation = (card, x, y)
                                        x += 236                                      // move next card over along x axis
                                        setSpriteDrpth (card, -1)
                                        setSpriteVisibility (card, true)
                                        drawSprites ( )
                                        sleep (.01)
                                        update ( )
                                        sleep (.07)
                                      repeat
                                     getButton ( )
                                     selection  ( )
                                  sleep (10)
                                  //...............................................................................
                                  
                                  function shufflePack ( )
                                      for i = 0 to 1000 loop
                                      cardIndex1 = random (52)
                                      cardIndex2 = random (52)
                                      card1 = cards [cardIndex1]
                                      card2 = cards [cardIndex2]
                                      cards [cardIndex1] = card2
                                      cards [cardIndex2] = card1
                                     repeat
                                  return void
                                  //..............................................................................
                                  
                                  function getPack ( ) 
                                      values = [  [0,"2"], [1,"3"], [2,"4"], [3,"5"], [4,"6"], [5,"7"], [6,"8"], [7,"9"], [8,"10"], [12,"A"], [9,"J"], [11,"K"], [10,"Q"]  ]
                                      image = 0
                                      for suitNo = 0 to 4 loop
                                        for valueNo = 0 to 13 loop
                                       cardNo = suitNo + 13 = values [valueNo] [0]
                                       card = createSprite ( ) 
                                       cardImage = getImage (imageNo)
                                       setSpriteImage (card, cardImage)
                                       setSpriteVisibility (card, false)
                                       size = getSpriteSize (card)
                                       setSpriteOrgin (card, -size.x/2, -size.y/2)
                                       scahle = 1.6
                                       setSpriteSchale (card, {schale, schale} )
                                       cardValue = values [valueNo] [ 1 ]
                                       cardSuit = suits [suitNo]
                                       card.imageNo = imageNo
                                       cards [cardNo] = card
                                          image += 1
                                     if imageNo == 39 then  // this is the Joker
                                        imageNo +=1             // skip this card
                                     enfif
                                    repeat
                                   repeat
                                  return void
                                  //..................................................................................
                                  
                                  function getImage (imageNo)
                                     cardImage = createImage ( 140, 190, false, image_rgb)
                                     setDrawTarget (cardImage)
                                     drawSheet (deck, imageNo + 15, {0,0, 140, 150} )
                                    update ( )
                                  return cardImage
                                  //...........................................................................
                                  
                                  function getButton ( )                                   // red buttons
                                     for i = 0 to 5 loop
                                       Box (q, 550, 160, 70, {1, 0, 0, 1} false)
                                       q += 236
                                       playAudio (0, sndeff3, .5, .5, 2, .1)
                                     update ( ) 
                                     sleep (1)
                                    repeat
                                  return void
                                  //...............................................................................
                                  
                                  function selection ( )  // select whitch card to discard
                                       deleteShape (Box2)
                                       Box2 = createBox (r, 583, 160, 40)
                                       setVertexColor (Box2, 0, {1, 1, 1, 0, .1} )
                                       playAudio (0, sndeff4, 3, .5, 2, .1)
                                       drawShape (Box2)
                                       sleep (.5)
                                       
                                       c = controls (0)
                                  
                                          if c.left and !oldL then
                                               r = (r - 236)
                                            setSpriteLocation (Box2, r, 583)
                                            playAudio (0, sndeff4, 3, .5, 1, 0)
                                              if r < 160 then r = 1104
                                            endif
                                          endif
                                  
                                  if c.right and !oldR then
                                               r = (r + 236)
                                            setSpriteLocation (Box2, r, 583)
                                            playAudio (0, sndeff4, 3, .5, 1, 0)
                                              if r < 1104 then r = 160
                                            endif
                                          endif
                                   
                                   oldL = c.left
                                   oldR = c.right
                                  
                                  return void
                                  //........................................................................................
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • M
                                    Maxwello F last edited by

                                    Is the controls (c=controls(0)) in the right place?

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

                                      I'm not really sure about your controls, but I think you may be approaching the entire concept of a game program in a slightly strange / unusual way.

                                      Your code says it has a main loop but I don't really see one and you have a bunch of sleep commands in there which suggest to me you are trying to control the flow of time which will ultimately lead to a drop in frame rate and responsiveness of a program.

                                      Pretty much every program that runs for a indeterminate amount of time (as in, doesn't just do something end exit) is going to have a loop something along these lines:

                                      loop
                                          // Clear screen every frame
                                          clear()
                                      
                                          // Do stuff
                                      
                                          // Update screen (will automatically wait for VSync of 60fps if program is running fast enough
                                          update()
                                      repeat
                                      

                                      You then need to do everything inside that main loop realising that it will be called anything up to 60 times a second. Don't try to slow it down. If you need to do something less often than 60 times a second, put a counter in there and count the number of times it's been through the loop and if you want to do something every 5 seconds, only do it if count % (5 * 60) == 0

                                      That's a primitive approach but works fine until you see your fps dropping below 60, then you need to rethink it.

                                      [EDIT] Quickly looking at your code again I think this might well be why your code isn't reading your buttons more than 5 times. Your entire program is only looping 5 times before sleeping for 10 seconds and then quitting. Unless I'm really misreading something!

                                      A game if Fuze needs to contain an infinite loop somewhere to work.

                                      1 Reply Last reply Reply Quote 5
                                      • K
                                        kendog400 F last edited by

                                        Is there a moveShapeLocation command in fuze ? I'm trying to move the box horizontally so as to select a card for discard, If I put in drawShape then it puts in additional boxes and then defeats the purpose of selecting a card..... Mabey I cuuld put in another if command to put a box over the previous box and then clear the previous selcetion box.....

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

                                          In the example above https://fuzearena.com/forum/topic/900/left-right-joycon-buttons-dont-work/13

                                          setShapeLocation(Box2, r, 583)

                                          1 Reply Last reply Reply Quote 0
                                          • K
                                            kendog400 F last edited by

                                            I tried to use the setShapeLocation, but it seems to want a drawShape Command under it, and this is whats causing it to add more boxes each time the left / right is pressed...Is there any way around this ?....I'm trying to figure out something tricky like delete the previous box or draw another box oxer the previous box when I press left / right for a second or third time....

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