Navigation

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

    Dynamic Function Arguments?

    Advanced
    function print help arguments dynamic
    3
    5
    601
    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.
    • H
      HeavyByte last edited by

      Is there a keyword to access the arguments of a function as an array, similar to how the built in print function works?

      I am trying to write a print line function that basically wraps print() but adds a new line char at the end. I know that I could just pass my arguments as an array and use a for loop to concat the string but that seems too messy and a waste.

      Thank you for all the help!

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

        I’m afraid it’s not possible. But you can concatenate strings with + instead of using , and that way you can use the same arguments to your own print function and the built-in one...

        H 1 Reply Last reply Reply Quote 0
        • H
          HeavyByte @vinicity last edited by

          @vinicity Thanks! I really liked how clean the syntax was with commas so I think I'll just stick with adding "\n" manually at the end of everything.

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

            You could write something like this:

            function joinArray(values, separator)
                string result = ""
                int i
                for i = 0 to len(values) loop
                    if i > 0 then
                        result += separator
                    endif
                    result += str(values[i])
                repeat
            return result
            
            function printLn(value)
                print(value + "\n")
            return void
            
            // then call like this:
            string joined = joinArray([1, 2, "test", [.example = true] ], "\n")
            printLn(joined)
            
            H 1 Reply Last reply Reply Quote 1
            • H
              HeavyByte @PB____ last edited by

              @PB____ yeah, that's what I was trying to avoid. I'd rather just type the extra "\n" and save the extra syntax and compute cycles. Thank you though!

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