Left-Right Joycon buttons dont work
-
@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
-
I think you're right, I do need to go through the tutorials more than once....
-
Up front, my apologies if I have the wrong idea about where you're struggling...
Games can be a bit of a strange concept at first and I have a feeling this is what's tripping you up. Actually not just games, anything that constantly dynamically changes and never stops, but whilst Fuze is certainly not limited to game creation, it's seems to be the thing it's most used for so I'll stick to that here.
So you need to get into the frame of mind that your code is never going to stop. You will always have a loop and in it's most simplest form, at least until you hit performance problems, assume that 60 times a second you are going to be expected to completely erase the screen and re-draw it. Like I say, try and do too much that won't fit into that 60fps time frame and you'll have to think about not clearing the entire screen, but forget about that for now.
So your program will be a loop, or a series of loops. Consider this "pseudo-code":
loop loop until gameStarted // Draw attract screen repeat loop until gameOver // Do gameplay // Update game state // Clear and redraw screen repeat // And so on repeat
All of that is very high level and not really anything to do with your specific questions. BUT, I have a feeling that understanding that concept a bit better may remove some of the questions that you're having? (I may be wrong of course). The thing is that is never stops. It's unusual to have sleep commands. I'm sure they have their uses but I personally wouldn't miss then if they were not in the language and you seem to have quite a lot of them.
The other thing then is the question of this selection box:
Mabe I could put in another if command to put a box over the previous box and then clear the previous selection box.....
So, you shouldn't really need to be worrying about clearing the previous selection box, or any of that jazz. I'm sorry, I've not followed exactly what you are wanting to do. But let's say that you have 5 cards laid on the table in a row and you want a red box around the first card. When the player moves right the selection box moves to card number two, then 3, or press left and it's back to card 2 and so on.
All you need to do is track two things: 1) is the selection active at all (are we in selection mode), if so 2) which card is selected (1, 2, 3, 4 or 5). You would increment the selection when the user presses left or right.
So now, you have the info you need to just draw a box if selection is active and you know which card it has to be drawn around. And you draw it EVERY frame (every time the loop repeats), regardless, but only as long as selection is enabled. And remember that you do this without any pauses or sleeps, forever, or until the game progresses to the next phase (the user selected a card perhaps?)
Again, my apologies if I have got the wrong end of the stick. Or rather, I've misunderstood where you are getting stuck (or coming unstuck).