Navigation

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

    Hints and Tips

    General Discussion
    25
    60
    8362
    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.
    • Discostew
      Discostew F @pianofire last edited by

      @pianofire I honestly didn't feel they would be good there, in my opinion. It's a place to ask, mainly directed at the devs for improvements and additions to FUZE itself. Perhaps this Hints and Tips page isn't really a good place either, but it felt the best of the two. Maybe a page dedicated to user-made code that's beneficial to all?

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

        @Discostew No they are fine here. I meant that the language should probably have these functions built in

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

          @pianofire Oh yes, definitely. These functions have to juggle the creation of strings each time it needs to make a change. Might that cause some out-of-memory issues like what we've been seeing lately?

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

            Out of memory issues need to get fixed and become a non-issue!

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

              Posted this in response to a question elsewhere and @pianofire rightly suggested it be put in hints and tips.

              Here is a really handy breakPoint function used by JonBoy in many of his programs. Really useful if you want to stop your program at any point check a value/values:

              function breakPoint( info )
                  press = false
                  while !press loop
                      j = controls(0)
                      if j.x then 
                          press = true
                      endif
                      clear()
                      print( "Breakpoint: ", info )
                      print( "Press X to continue" )
                      update()
                  repeat
                  sleep( 0.2 )
              return void
              

              Simply call the function, pass it what you want to see and Bob is your proverbial uncle.

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

                Hi folks, just to let you know as I don't think this is as apparent as it should be...

                You can copy and paste code between projects. When you copy code to the clipboard, the clipboard is kept when you open a new project.

                This allows you to "transfer" important sections of code, for example, a whole load of music data, between projects.

                If it's images or maps you want to transfer, you can do this from the image and map editor file managers. Press the X button when viewing the thumbnail for an image or map, then select "copy image" or "copy map", then choose the project file to copy to!

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

                  I am not sure how useful this is really. I was experimenting with saving variable length data to a file and came up with this:

                  text = [ "The", "Quick", "Brown", "Fox" ]
                  
                  // Write to file
                  handle=open()
                  entries = len(text)
                  write(handle, padstr(str(entries), 4, " "))
                  for i = 0 to entries loop
                    write(handle, padstr(str(len(text[i])), 4, " "))
                    write(handle, text[i])
                  repeat
                  close(handle)
                  
                  //Read back from file
                  handle = open()
                  entries = int(read(handle, 4))
                  for i = 0 to entries loop
                    strlen = int(read(handle, 4))
                    print(read(handle, strlen),"*")
                  repeat
                   
                  update()
                  sleep(3)
                   
                  function padstr(string, padlen, padchar)
                    result = string
                    while len(result) < padlen loop
                      result = result + padchar
                    repeat
                  return result
                   
                  
                  Jaywalker Zypher 2 Replies Last reply Reply Quote 4
                  • pianofire
                    pianofire Fuze Team last edited by pianofire

                    You can create sprites in code by using setDrawTarget to draw onto an image rather than the screen buffer and then create a sprite from the image

                    palette = [ black, red, white, grey, blue, yellow, green, deeppink ]
                    
                    shipData = [ 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                 0, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                 1, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                 0, 1, 7, 7, 3, 3, 3, 3, 3, 4, 4, 5, 0, 0, 0,
                                 1, 3, 7, 7, 7, 7, 3, 3, 3, 3, 3, 3, 3, 2, 6,
                                 0, 0, 7, 7, 7, 3, 2, 6, 0, 0, 0, 0, 0, 0, 0 ]
                    
                    shipImage = createImage(15, 6, false, image_rgb)
                    setDrawTarget(shipImage)
                    for x = 0 to 15 loop
                      for y = 0 to 6 loop
                        pixel = shipData[ y * 15 + x ]
                        if pixel > 0 then
                          plot(x + 1, y + 1, palette[pixel])
                        endif
                      repeat
                    repeat
                    update()
                    
                    ship = createSprite()
                    setSpriteImage(ship, shipImage)
                    setSpriteScale(ship, { 10, 10 } )
                    setSpriteLocation(ship, gwidth() / 2, gheight() / 2)
                    
                    loop
                      drawSprites()
                      update()
                    repeat
                    
                    N Discostew 2 Replies Last reply Reply Quote 2
                    • Jaywalker
                      Jaywalker Donator @pianofire last edited by

                      @pianofire So you are storing metadata file information in the 4 first chars and that way you know how long the contents are. Good approach!

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

                        @pianofire Thanks for the code sample regarding creating the sprite in code. However, we need to know if the pixel-based coordinate system is 1-based or 0-based, as discussed elsewhere. Your code will obviously break it it's changed to 0-based.

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

                          Yes it appears to be 1-based at the moment. I only noticed that this morning

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

                            @pianofire That's a similar approach to using uploadImage(), but rather than referencing the colors directly in the Data, you index to them and plot the pixels yourself. Honestly though, I wish we had the ability to load indexed-images and not just direct-color images, and then be able to edit the palette to alter all referenced pixels on the next draw call, like how the NES, SNES, Genesis, etc did it.

                            (Just to note, your code might error out due to out-of-boundaries, as shipData only contains 15x6 entries, but plotting can reference 16x16 entries)

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

                              @Discostew agreed but this way you can use any of the drawing commands not just plot. Why don't you add the palette colour image request to the wishlist?

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

                                @pianofire Have to see whether I requested the indexed-image support in the Wishlist. I think I did.

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

                                  @Discostew Yes you did https://fuzearena.com/forum/topic/11/wishlist/11

                                  1 Reply Last reply Reply Quote 0
                                  • N
                                    Nisse5 F last edited by Nisse5

                                    If you want to be able to return from a function at any point, here's an approach I also use for various other programming languages.
                                    By using a "one-pass loop", you can make the function behave as if it has a return statement from any place. (The technique can be used for other situations than function returns as well.)

                                    Here's a simple example:

                                    function myFunction(arg)
                                        retval = false
                                        while true loop
                                           if (arg <= 0) then break endif   // First "function return"
                                           print("Argument is positive\n")
                                           if (arg > 100) then break endif // Second "function return"
                                           print("Argument is less than 100\n")
                                           if (arg % 10) then break endif // Third "function return"
                                           print("Argument is not divisible by 10\n")
                                           // And so on...
                                           retval = true
                                           break // This line is crucial, otherwise it becomes an endless loop!
                                        repeat
                                    return retval
                                    // End of function
                                    
                                    Discostew 1 Reply Last reply Reply Quote 3
                                    • pico8-jihem
                                      pico8-jihem F last edited by

                                      Hello, I made a console to facilitate debugging. Let me know if you're interrested in. It's a shared program.

                                      N 1 Reply Last reply Reply Quote 5
                                      • N
                                        Nisse5 F @pico8-jihem last edited by

                                        @pico8-jihem I tested your debug console right now. Very handy!

                                        Feature request: how about d-pad up/down to browse up/down? D-pad down would basically be the same as the A button.

                                        1 Reply Last reply Reply Quote 0
                                        • Discostew
                                          Discostew F @Nisse5 last edited by

                                          @Nisse5 It's good, but once you get into utilizing actual loops in a function, including nested ones, and you want to have the function return from within those, you'll have to make a break case after each one.

                                          1 Reply Last reply Reply Quote 1
                                          • Spacemario
                                            Spacemario F last edited by

                                            I've wrapped up a first version of my template program, which could be used as the start of a game! It displays graphics, gets user input, and plays music plus sound effects. It even "filters" the input with a simple polling implementation, which is nice when you don't want menu cursors going ninety miles per hour. You can see it via my friend code, feel free for anyone to add me:

                                            SW-1537-8645-5886

                                            One caveat about the polling: If I call "setTimer" only when a button is pressed, like should happen, I get a very weird error. So in the template, I'm setting the timer every frame: not quite right, but it doesn't crash.

                                            In my other shared project, the polling code works perfectly, and I copy and pasted it from there. Weird! I'll do a separate post about this in the future if I dig more, and it doesn't look like a bug in my own code.

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