Left-Right Joycon buttons dont work
-
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() -
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
-
This post is deleted! -
This post is deleted! -
This post is deleted! -
I will rotate that for you!
-
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
-
@kendog400 what does the last argument in the play audio do?
-
@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)
-
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
-
@SteveZX81 just beat me to it lol
-
@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!
-
@pianofire really helpful I put code where it is because other people put it there but now I understand why.
-
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 //........................................................................................
-
Is the controls (c=controls(0)) in the right place?
-
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.
-
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.....
-
In the example above https://fuzearena.com/forum/topic/900/left-right-joycon-buttons-dont-work/13
setShapeLocation(Box2, r, 583)
-
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....
-
I genuinely think you need to spend some time going through the tutorials.
Similar to my example above, yes, the setShapeLocation command does indeed require you to later call the drawShape() command. You would do something along these lines:
x = 50 y = 50 width = 50 height = 50 myBox = createBox(x, y, width, height) loop clear() // Call a routine to modify X and Y as desired setShapeLocation(myBox, x, y) drawShape(myBox) update() repeat
Thats if you want to use shapes.
If not, how about:
x = 50 y = 50 width = 50 height = 50 loop clear() // Call a routine to modify X and Y as desired box(x, y, width, height, red, false) update() repeat