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.
    • 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
              • Zero Division
                Zero Division @Discostew last edited by

                @Discostew The string slice tricks you posted came in handy!

                1 Reply Last reply Reply Quote 0
                • Zero Division
                  Zero Division last edited by

                  On the Programs screen, you can toggle between the example programs and your own programs from the keyboard using CTRL-R and CTRL-L. Handy to avoid having to reach for a controller.

                  Wanderer1412 K 2 Replies Last reply Reply Quote 0
                  • Wanderer1412
                    Wanderer1412 Donator @Zero Division last edited by

                    I don't think you actually need the CTRL key. Just "r" or "l" on the keyboard works for me.

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

                      One thing to take into account when working with any language that runs under an interpreter is that every character in code counts towards CPU usage. For instance, a variable name that is 16 characters long is going to take longer to parse in the interpreter prior to processing its contents than a variable name that's only 4 characters long. I do believe that comments are ignored, so they shouldn't interfere with the parsing scheme, thus won't affect CPU usage.

                      Just be sure to comment on what things do if you do decide to shorten variable names. Don't want to forget what something does because the name becomes less readable.

                      I was quick in my assumption that this was the case, but it is not. Variable name length doesn't have an impact on speed.

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

                        In relation to my post above, be sure to use the keyword local when defining variables in functions that also have a global counterpart. I just ran through an interesting collision of this when I threw c = controls(0) out of the main loop (so c could be global), and it screwed up my entire MML program during playback. That was because for shortening code in various functions I made, where I'd use c to define a channel that was to be processed. It was odd though because technically, I was done using controls by the time it came to execute my MML_update() function, and once I was done using the c variable in my functions, I write-back to the channel structure, so if c was rewritten, it shouldn't have affected anything. But it did.

                        Spacemario 1 Reply Last reply Reply Quote 1
                        • M
                          MikeDX last edited by

                          this local keyword doesn't exist. what you are experiencing there is not by design but a fault in the parser.

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

                            @MikeDX Huh, well in either case, it did something to prevent it from screwing up, even if unintentional. But if it has been fixed in the update, then I'll need to clean my code to remove it.

                            1 Reply Last reply Reply Quote 0
                            • Zero Division
                              Zero Division @Discostew last edited by

                              @Discostew Not sure this is really true. Depends on the interpreter's implementation. If it parses to bytecode before execution, this might be a non-issue; variable names are probably not kept and likely simply become pointers under the hood. If it's a syntax-directed interpreter, you may be right.

                              Zero Division 1 Reply Last reply Reply Quote 0
                              • Zero Division
                                Zero Division @Zero Division last edited by

                                @Zero-Division @Discostew

                                I usually strip out identifiers at the lexical analysis phase, so they're gone before parsing begins. The token stream produced retains the begin and end indexes into the original source code file for each token, which allows for things like printing error messages that reference the line and column where something blew up, recovering the name of a function, etc.

                                Anyway there are so many ways to do it that I think we should resolve to measure the performance of FUZE on shared benchmark programs before making any assumptions about its performance characteristics: otherwise we're operating on pure speculation/superstition.

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

                                  @Zero-Division Dunno why I didn't do a simple test until now, but my assumption was wrong in thinking that shorter variable names produced faster results. I must have done some small but significant change with my code at the same time that resulted in faster processing.

                                  Zero Division 1 Reply Last reply Reply Quote 1
                                  • K
                                    kendog400 F @Zero Division last edited by

                                    On nitendo swotch this would be R1 (right top button) (user section) or L1 (preset Pgms)

                                    1 Reply Last reply Reply Quote 0
                                    • Zero Division
                                      Zero Division @Discostew last edited by

                                      @Discostew I suspected as much. We really need a way to get the text of a program off of the switch to share online that's less onerous than screenshots. Then we can really start to science the performance characteristics of FUZE with benchmarks.

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

                                        This post is deleted!
                                        pianofire 1 Reply Last reply Reply Quote 0
                                        • pianofire
                                          pianofire Fuze Team @Zypher last edited by

                                          This post is deleted!
                                          1 Reply Last reply Reply Quote 0
                                          • Spacemario
                                            Spacemario F @Discostew last edited by Spacemario

                                            @Discostew I was totally unaware of this, thanks!

                                            EDIT: I posted before I read that the "local" thing might be a fluke. Either way, very interesting!

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