Announcement

Collapse
No announcement yet.

Variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Variables

    In uscript is it possible to pass the name of an array to a function rather than passing the whole array?

    #2
    Generally all parameters are passed by value, i.e. they are copied. For Object variables (i.e. anything you can call functions on) the object refrence is copied and the copy is passed by value. There's no way to change that behavior.

    ...and before anyone brings this up: No, the "out" parameter modifier does not change it into by-reference passing. It merely copies the modified (or not modified) value back to the original variable passed as function argument. In other words it costs twice the performance as a regular parameter.


    You only option is to wrap the array in an Object and pass the object reference around.

    Comment


      #3
      The name of a variable is just a refference to the variable, you see it as text, UCC compiles it as machine code, the name itself is never refferenced in the compiled code only it's location in code and it's value.

      There is no way to pass the name of variable to a function.

      Comment


        #4
        Well, you could pass the variable name as a string and then get the variable content as another string using GetPropertyText(), but that's limited to class properties and highly impractical for array or struct values.

        Comment


          #5
          The array is already part of an object. If you're only using the same class objects, just pass a reference to the object containing the array.

          Comment


            #6
            That's only true for array properties in a class, but not for local variables or when you want to access one of several array properties.

            Comment


              #7
              Hadn't even thought of that. Shows how much use I've had for such a construct. :weird:

              Comment

              Working...
              X