Navigation

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

    Assigning a value to a structure element that figures as argument in a function

    Help
    3
    8
    224
    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.
    • emptytheory
      emptytheory F last edited by

      I'm not sure if that title makes sense, but I'll try to explain.

      a = [.b = 0]
      function c(d)
          d = 1
      return void
      c(a.b)
      

      After running this function, the value of a.b is still 0. It seems I can't change the value of a.b to 1 by feeding it into a function that changes the value of its argument to 1. Is such a function impossible? Can someone explain why and tell me if there is another way of doing this?

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

        you are passing the value not the refence, you could do a.b = c(a.b)

        emptytheory 2 Replies Last reply Reply Quote 1
        • emptytheory
          emptytheory F @MikeDX last edited by

          @MikeDX I'm afraid I don't understand the terminology. What does it mean to pass a reference?

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

            @MikeDX I think I get it now. What goes into the function is the value of a.b, whatever that is.

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

              that's right. you are sending it the value and not the variable

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

                But if you declare an array of the structure, I strongly believe you would pass a reference (that's how array is usually implemented). Here is the code I use:

                {code}
                struct sometype
                float elevation
                ...
                endStruct

                sometype terrainHeightMap[32][32]

                function setup(terrainMap)
                for x=0 to 32 loop
                for y=0 to 32 loop
                terrainMap[x][y].elevation = ... // whatever you want here
                repeat
                repeat
                return void

                // Later on:
                print(terrainHeightMap[10][10].elevation)
                {code}

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

                  that is true but he has passed a.b and not just b 👍

                  1 Reply Last reply Reply Quote 0
                  • mixaal
                    mixaal F last edited by mixaal

                    Yes, exactly, that was my 2 cents on how to assign a value into structure, when needed. Not sure what happens if the whole structure is passed as an argument, if that is a reference or a value. Mu guess is by value ;-). I.e in this what would happen if only a is passed and the function would assign a.b=3

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