Navigation

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

    Initialization logic with structs

    General Discussion
    3
    3
    235
    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.
    • PB____
      PB____ last edited by

      I noticed behavior of structs in FUZE that I think can be really useful, but I'm not sure if this is a supported way of doing things. Maybe I'm not the first to notice, but I wasn't aware of it anyway.

      In FUZE you can do the following thing:

      function userFunction_time()
      return time()
      
      function userFunction_controls(i)
      return controls(i)
      
      var example_initialization_index = 0
      
      struct example
          time = userFunction_time()
          controls = userFunction_controls(example_initialization_index)
      endstruct
      
      example values_Before
      
      example_initialization_index = 1
      
      example values_After
      

      After this values_Before.controls contains the result of controls(0) and values-After.controls contains the result of controls(1). Also the .time property contains the result of time() when the struct was initialized.

      So this suggest that you can use user functions to define initialization logic with structure properties (and that initialization logic can have side effects as well).

      I notice it only works with user functions, not with system functions, but like I show in the example, you can call system functions within those user functions. So that's not that limiting.

      However, I was wondering if this behavior is intentional and safe to use in code, or if this is an "undocumented feature" that may be removed or changed in a later build?

      1 Reply Last reply Reply Quote 5
      • RodrigoDavy
        RodrigoDavy last edited by

        This is awesome, I hope they don't remove it :)

        In OOP, this would be like a data class with a constructor

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

          I'm using this method too. That is calling a function to set a parameter in a struct. In my case I am using it to set which sprite and which path from a predetermined table that changes during the game levels.
          It's quite helpful.

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