Announcement

Collapse
No announcement yet.

Dynamic Array Help

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

    Dynamic Array Help

    hi guys, i want to create a function that can get a dynamic array of any actors and use it. let me explain.
    one case the function might be called for an array of pawn class and sometimes with the Inventory.
    instead of creating the same function for
    Array<Pawn> Array<Inventory> and so on. if its possible to do it for every actor object. some kind of casting or something else.

    #2
    Is this a question?

    I normally see a different structure for overloading functions in languages that don't support the feature, but don't see a technical barrier to your doing it.

    Put your code for the function here that you attempted.

    Comment


      #3
      i have like Array<Pawn> and Array<UDKHUD> and so on to call this function and i dunno how to do it. thanks

      static function SetActorArrayToJson(JsonObject json, Array<Actor> arr, string arrName)
      {
      local int i;
      json.SetStringValue(arrName $ "_Length", arr.Length);
      for(i = 0; i < arr.Length;i++)
      {
      json.SetStringValue(arrName $ "_Items_" $ string(i),PathName(arr[i]));
      }
      }

      Comment


        #4
        Isn't that function saving?

        Are you asking about saving different types of arrays to json?

        Comment


          #5
          yup. i want to save different arrays to json and i dont want to write that code everytime from scratch so i wrote a function but i have no idea how to cast the the arrays

          Comment


            #6
            UnrealScript doesn't have generics.

            One way is to use Array<Object>, then your going to have to have a section of if's where you attempt casting each type, test to see if it's not none, if it's not you have your type and do your specific save.

            Edit: I see a problem with that because of inheritance. So, you'll need to test for the higher types last. ie. your last test would be for Actor.

            Comment


              #7
              lol i tried it now. and it works great apparently no casting at all requires. for example:
              Array<UDKHUD> huds;
              ..
              ..
              ..
              SetActorArrayToJson(json,huds,"HUDSARR");
              and it works great. thank you very much for your help

              Comment

              Working...
              X