Navigation

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

    Looking for help with array and randomness

    Help
    6
    20
    825
    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.
    • Jonboy
      Jonboy Fuze Team last edited by

      I think this should be:

      while !used[a] loop

      meaning keep looping while used[a] is equal to 0

      Unless i've missed something, which is entirely possible!

      Personally for legibility i would use:

      while used[a] == false loop

      Purely force of habit so i do get told off sometimes by the youngsters!

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

        OK, thanks, I finally got that PGM working. But I have another question : I have here a program that displays cards, along the "X" axis, then after 13 cards it moves down the "Y" axis to start another row, but every time it displays a card, the previous card disappears, I'm trying to figure out how to make the previous card stay on the screen. I would like to get all 52 cards on the screen....I tried to setSpriteVisibility (card, true), but nothing seems to work, Heres a example of the program :

        //..................................................................
        card = createsprite ( )
        deck = loadImage ("Kenneyboardgames")
        tiles = numtiles (deck)
        setspriteimage (card, deck)
        x = 150
        y = 200
        setspritelocation (card, x, y)
        setspriteanimation (card, 0, 64)
        tile = 15
        loop
          clear (darkGreen)
          c = controls (0)
          if c.a and tile < tiles -1 then
            tile += 1    
        setspriteanimation (card, 0, 67)
          x = x += 80                           // move along the "x" axis
          setspritelocation (card, x, y)
            if x > gwidth() - 180 then    // once you go 13 cards across
              x = 70
              y = y += 100                     // move down the "y" axis to start a new row
                endif                               // end the 2nd if statment
        updatesprites ( )
        drawsprites ( )
        update  ( )
        endif                                       // end the 1st if statment
        setspriteschale (card, 1.5, 1.5)
        setspriteanimframe (card, tile)
        
        // at this next line I would like to end the program with the end ( ) function, instead it goes back to the beginning...
          if tile > 67 then tile = 15 
            endif
          if tile == 54 then
            tile += 1                      // skip the joker
              endif
        drawsprites ( )
        update ( )
        repeat                             // end of program....
        //...........................................................
        
        // here i have an example of an end Function....It worked with other Programs, but not this one....
        function end ( )
          clear(lime)
          drawtext (120, 250, 180, black, "End of Deck")
          update()
          sleep(3)
        return void
        
        pianofire 1 Reply Last reply Reply Quote 0
        • K
          kendog400 F last edited by

          Does Fuze have a Drop Shadow effect, like Photoshop ? (Just wondering)

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

            @kendog400 Your program only has a single sprite. When you change the animation and location of that sprite it just moves and changes that single sprite. If you are going to use sprites you need to have a sprite for each card in the pack. The easiest way to do that is to use an array of sprites. I have shared an example of this.

            The end function will not terminate your program it will just be called every time around the game loop. Instead you need to make your game loop conditional. Something like

            finished = false
            while !finished loop
              // set finished = true to end program
            repeat
            
            clear(lime)
            drawtext (120, 250, 180, black, "End of Deck")
            update()
            sleep(3)
            
            1 Reply Last reply Reply Quote 1
            • K
              kendog400 F last edited by

              OK, thanks, I'LL try this to see if I could get the program to end after the deck of cards is used up...

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

                As for a drop shadow effect, mabey i could put a rectangle under the sprite, re-set the opacity, then add a blur... (?)

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

                  I tried, but it seems I dont know exactly where to put the while loop......I tried to replace the for loop with the command while....It must be some sloppiness on my part.....could you give me a hint ?......

                  pianofire 2 Replies Last reply Reply Quote 0
                  • pianofire
                    pianofire Fuze Team @kendog400 last edited by

                    @kendog400 Sorry very busy at the moment. I will take a look on Wednesday

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

                      @kendog400 My friend code is 5139-4176-1902

                      Please add me as a Nintendo friend, share your project and I'll take a look today if I can!

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

                        @kendog400 OK I think that it is worth you looking at the 3 main different types of loop in Fuze: https://fuzearena.com/help/view/loop

                        1. Infinite (loop ... repeat) - this doesn't end until it is interrupted (as in your program)
                        2. Conditional (while condition loop ... repeat) - ends when the condition is met (e.g. the game has finished)
                        3. For (for index = start to end loop ... repeat) - ends when index > end

                        You wouldn't normally use 1) as it can only be ended by stopping the program.
                        You would use 2) when you want something to carry on until something happens
                        You would use 3) when you have a fixed amount of work to do

                        In your example you could use 3) because you have a fixed amount of work - you deal the cards and then your program finishes.

                        In reality your program will probably want to do something else after dealing the cards so you would have loops inside loops

                        Here is an example of a simple game loop (and possibly the worlds dullest game)

                        finished = false
                        
                        while !finished loop
                          gameScreen()
                          endScreen()   
                        repeat
                        
                        function gameScreen()
                          c = controls(0)
                          while !c.a loop
                            clear()
                            c = controls(0)
                            printAt(0, 0, "Game Screen. Press A to exit")  
                            update()
                          repeat
                        return void
                        
                        function endScreen()
                          c = controls(0)
                          while !c.x and !c.y loop
                            clear()
                            c = controls(0)
                            printAt(0, 0, "End Screen. Press Y to play again and X to exit")  
                            update()
                          repeat
                          finished = c.x
                        return void
                        
                        QIsLegit 1 Reply Last reply Reply Quote 3
                        • QIsLegit
                          QIsLegit F @pianofire last edited by

                          @pianofire
                          Is there no way to break out of an 'infinite loop' using code?

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

                            @QIsLegit OK yes there is. You can use the break command but it is not good practice https://fuzearena.com/help/view/break

                            loop
                              c = controls(0)
                              if c.a then
                                break
                              endif
                              update()
                            repeat
                            
                            1 Reply Last reply Reply Quote 1
                            • First post
                              Last post