Copying Arrays

Get help using Construct 2

Post » Wed Feb 06, 2013 9:26 pm

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
B
5
Posts: 6
Reputation: 739

Post » Wed Feb 06, 2013 9:44 pm

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)
B
13
S
4
G
3
Posts: 75
Reputation: 3,425

Post » Wed Feb 06, 2013 9:47 pm

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...R0J0hound2013-02-06 21:48:03
B
79
S
24
G
54
Posts: 4,751
Reputation: 40,765

Post » Wed Feb 06, 2013 10:57 pm

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:



Where the Array within the For loops is smallArray

I think I have problems with the syntax relating to arrays
B
5
Posts: 6
Reputation: 739

Post » Wed Feb 06, 2013 11:52 pm

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.
B
5
Posts: 6
Reputation: 739


Return to How do I....?

Who is online

Users browsing this forum: mjj1990 and 5 guests