Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

Dynamic Arrays

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

  • Dynamic Arrays

    I was readying the new Unreal Development Kit Game Programming with Unrealscript: Beginner's Guide. I believe I found a mistake when it comes to compiling this array:
    //AwesomeActor Sprite
    class AwesomeActor extends Actor
    placeable; //Allows to be placed into editor
    var int TestArray[3];
    var array<int> CopyArray;
    function PostBeginPlay()
    {
    TestArray [0]= 9;
    TestArray [1]= 5;
    TestArray [2]= 6;
    CopyArray[CopyArray.length] = TestArray[CopyArray.length 1];
    CopyArray[CopyArray.length] = TestArray[CopyArray.length 1];
    CopyArray[CopyArray.length] = TestArray[CopyArray.length 1];
    `log("Copy array length:" @CopyArray.length);
    }
    defaultproperties
    {
    Begin Object Class=SpriteComponent Name=Sprite
    Sprite=Texture2D'EditorResources.S_NavP'
    HiddenGame=True
    End Object
    Components.Add(Sprite)
    }

    The intention was to have CopyArray be a dynamic array but it doesn't compile unless I add a plus or minus symbol. Is there a reason for this? Was their a mistake from the author? or did I miss something?

  • #2
    TestArray is a Array. CopyArray is a dynamic array.
    To add items to a dynamic array, you use Add or AddItem (or the method you were trying to do).

    http://udn.epicgames.com/Three/Unrea...es.html#Arrays
    http://udn.epicgames.com/Three/Unrea....html#DynArray

    I don't get the intention behind your code. You are changing the CopyArray dynamically and using the length to access a static array. It would result into a "out of bound" error.

    Code:
        TestArray [0]= 9;
        TestArray [1]= 5;
        TestArray [2]= 6;
        CopyArray[CopyArray.length] = TestArray[CopyArray.length - 1]; // CopyArray[0] = TestArray[0 - 1] // out of bound
        CopyArray[CopyArray.length] = TestArray[CopyArray.length - 1]; // CopyArray[1] = TestArray[1 - 1]
        CopyArray[CopyArray.length] = TestArray[CopyArray.length - 1]; // CopyArray[1] = TestArray[2 - 1]
        `log("Copy array length:" @CopyArray.length);
    If you want to copy an array (not a dynamic array) use a for loop and the ArrayCount function.
    Code:
    local int i;
    //CopyArray.Empty
    CopyArray.Length = 0;
    for (i = 0; i<ArrayCount(TestArray); i++) {
       CopyArray.Length[i] = TestArray[i];
    }

    Comment


    • #3
      you posted in the wrong forum this forum is for ut3 not udk you should repost in here http://forums.epicgames.com/forums/3...d-Unrealscript

      Comment

      Working...
      X