# Copying Arrays

1 favourites
• 5 posts
• I have two arrays BigArray is 100x100, and SmallArray is 10x10

Can anyone suggest the best method to copy a 10x10 portion of BigArray into SmallArray.

I have tried ForEach, For, loopindex.... and cant get anything to work.

Suggestions would really be appreciated before i pull all my hair out

• offsetx = X Location to Start Copy to in the BigArrray

offsety = Y Location to Start Copy to in the BigArrray

For "x" 0 to 9:

For "y" 0 to 9:

BigArray((offsetx + x), (offsety + y)) = SmallArray(x,y)

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• This is one way to do it where COL and ROW is the top left position to copy from.

local number COL=5

local number ROW=10

SmallArray: For each XY element

--- SmallArray: Set value at (SmallArray.CurX, SmallArray.CurY) to BigArray.At(COL+SmallArray.CurX, ROW+SmallArray.CurY)

Edit:

Too slow...

• RangerJim Thanks, would the following (copying portion of big into small)

For "x" 0 to 9:

For "y" 0 to 9:

SmallArray(x,y) = BigArray((offsetx + x), (offsety + y))

would this equate to this:

<img src="http://www.lesplayer.com/scirraforumimages/copyarray.png" border="0" />

Where the Array within the For loops is smallArray

I think I have problems with the syntax relating to arrays

• Rojohound... that works. Although the above For loop did not for the alternative For each loop does. Must be my interpretation of a For loop that's in error. Thanks.

• 5 posts