Navigation

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

    Function references

    Comments & Feedback
    4
    5
    380
    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.
    • sahara-min
      sahara-min last edited by

      I'm having a lot of fun playing around with F4NS so far! Here is a little feature suggestion:
      It would be useful to be able to store references to functions in variables/arrays/structs or pass them as arguments to other functions.
      Imagine being able to do something like this:

      array entity[100] = [ .position = { 0, 0 }, .behavior = noBehavior ]
      
      
      // Assign functions to .behavior on entities
      entity[0].behavior = playerBehavior
      entity[1].behavior = enemyBehavior
      entity[2].behavior = enemyBehavior
      entity[3].behavior = enemyBehavior
      
      
      loop
          updateEntities()
          update()
      repeat
      
      
      function updateEntities()
          for i = 0 to 100 loop
              entity[i].behavior(i) // Call the function assigned to .behavior
          repeat
      return void
      
      
      function noBehavior(i)
          // Do nothing
      return void
      
      
      function playerBehavior(i)
          // Do player stuff for entity[i]
      return void
      
      
      function enemyBehavior(i)
          // Do enemy stuff for entity[i]
      return void
      
      1 Reply Last reply Reply Quote 5
      • Discostew
        Discostew F last edited by

        I believe they are in the process of being able to call functions in this manner.

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

          @Discostew can you let me know where you heard this please so I can lookup the info. Thanks.

          1 Reply Last reply Reply Quote 0
          • Jaywalker
            Jaywalker Donator last edited by

            This should do the trick, however there are some limitations:

            The timer is set to 0 delay and unlimited repeats, so the timers must be stopped inside their function.
            The function will be called once because the interval is set to 0 seconds, so keep that in mind when implementing.
            Let me know if you have any more questions :)

            1 Reply Last reply Reply Quote 1
            • sahara-min
              sahara-min last edited by

              @Jaywalker That's pretty clever! Still would be nice to have proper function references though :)

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