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.
    • pianofire
      pianofire Fuze Team last edited by pianofire

      I will start with this one. In the help section I was struggling to work out how to copy the example code so that you could use it in a program.

      In the command reference you select a command in the left panel and then right arrow to select the panel. At this point the Y button (Copy code) does nothing. However if you now use the down arrow, first the syntax and then the example is highlighted. At this point the Y button will copy the selected code to the paste buffer. You get a "code copied to clipboard!" message.

      You can then return to the code editor and paste it. Sorry if this is obvious but it wasn't to me!

      EDSBWVRUcAAO4bm.jpg

      1 Reply Last reply Reply Quote 2
      • D
        doumdoum F last edited by

        Copy/Paste multiple lines of code, on a blank line. This will insert the code properly.

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

          Speaking of copy and paste.with your own code Hold the right trigger ZR and use the left dpad to select code. Then Y to copy. A to paste. Took me a few hours to figure that out.

          1 Reply Last reply Reply Quote 2
          • SteveZX81
            SteveZX81 F last edited by

            I'm sure this is going to be very helpful, great idea pianofire! (I have nothing to add right now, but perhaps in time)

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

              Don't know if this is mentioned anywhere, but L/R shoulder buttons will zoom the text size in both code and help windows.

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

                This is a great idea and there certainly should be more clarity on all of these. On to the to-do list!

                1 Reply Last reply Reply Quote 1
                • UKJEDI
                  UKJEDI last edited by

                  My tip may have already been figured out, but I found this incredibly useful, so if you don't know it, if you select to show the keyboard whilst in the help menus, the screen opens up to produce two windows; one for the code and one that displays the guides. With this you can type or copy the code whilst reading the guide at the same time. This allows you to view the code and read its meaning, plus changing certain variables allows to see what affects it has and gives you a better understanding of the code and it's instruction.

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

                    Fun with strings!

                    Turns out we have more flexibility with strings than initially thought. When loading the project "SoundFX Generator", I noticed some odd usage with regards to variables of type "string". Did a little testing, and I found out what they did. We have our string, and we have functions on how to find a string within a string, but did you ever wish you could just access parts of the string? Well, you can!

                    To access an individual character in a string at a specific location, access it like you would an array.

                    string name = "Discostew"
                    print ( name[3] )
                    
                    -- prints "c" --
                    

                    This is nice, but what if you wanted a "string" of characters from within a string? You could access each element individually and add them to another string, but why do that when you can do it in one go?

                    string mytxt = "The quick brown fox jumped over the lazy dog"
                    print( mytxt[4:] )
                    
                    -- prints "quick brown fox jumped over the lazy dog" --
                    

                    What this does is cuts off the first 4 characters of the string. Let's go even further with the same string

                    print( mytxt[4:8] )
                    
                    -- prints "quick" --
                    

                    This returns characters that cuts off everything before location 4 and after location 8. Because accessing a string in these manners returns a new string, you can access the new string in the same way on the same line

                    print( mytxt[4:][:4] )
                    
                    -- prints "quick" --
                    

                    This returns a string that cuts off the first 4 characters, then takes this new string, and cuts off everything after the first 5 characters (4+1). So here's what I've learned.

                    string[x] -- Returns the character at location "x" (base 0)
                    string[x:] -- Returns a string that truncates the first "x" characters of the source string
                    string[-x:] -- Returns a string containing the last "x" characters of the source string
                    string[:x] -- Returns a string that returns the first "x+1" characters of the source string
                    string[:-x] -- Returns a string that truncates the last "x-1" characters of the source string
                    
                    string[x:y] -- Returns a string that contains all the characters between x and y
                    
                    From this point, things get complicated, when x is greater than y, or if either x or y are negative
                    

                    Hope this is useful for people.

                    Zero Division 1 Reply Last reply Reply Quote 23
                    • Discostew
                      Discostew F last edited by

                      upper() and lower() functions for your string purposes!

                      function upper( strdata )
                        strlen = len( strdata )
                        for i = 0 to strlen loop
                          char = chrVal( strdata[ i ] )
                          newChar = chr( char - 32 )
                          if ( char >= 97 and char <= 122 ) then
                            strdata = strdata[:i + -strlen -1] + newChar + strdata[i + 1:]
                          endIf
                        repeat
                      return strdata
                      
                      function lower( strdata )
                        strlen = len( strdata )
                        for i = 0 to strlen loop
                          char = chrVal( strdata[ i ] )
                          newChar = chr( char + 32 )
                          if ( char >= 65 and char <= 90 ) then
                            strdata = strdata[:i + -strlen -1] + newChar + strdata[i + 1:]
                          endIf
                        repeat
                      return strdata
                      
                      
                      1 Reply Last reply Reply Quote 5
                      • Jaywalker
                        Jaywalker Donator last edited by

                        Thanks man! Is there a way to save posts in my favourites? ^^

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

                          These should probably be added to the Wish list

                          Discostew 1 Reply Last reply Reply Quote 0
                          • 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
                                            • First post
                                              Last post