Move a row in a 2d array to the left

Get help using Construct 2

Post » Mon Apr 01, 2013 7:19 pm

Hey everyone,

I need the most compact way to move an array row to the left ... like this ...

[ ][ ][N][N]
[ ][N][N][ ]

It also needs to switch from one side to another like this ...

[N][N][ ][ ]
[N][ ][ ][N]

Thanks for all the suggestions !
B
38
S
16
G
17
Posts: 2,230
Reputation: 17,220

Post » Mon Apr 01, 2013 7:47 pm

I need the most compact way to move an array row to the left ... like this ...

[ ][ ][N][N]
[ ][N][N][ ]


You could push a new element X element on the front of the array. If that's not appropriate, you could move all the XY values to a temporary array, and then cycle through the temporary array to reassign each X,Y to the original arrays X+1,Y.

It also needs to switch from one side to another like this ...

[N][N][ ][ ]
[N][ ][ ][N]


I'm not sure what is being switched in this example.
B
55
S
17
G
8
Posts: 339
Reputation: 11,736

Post » Mon Apr 01, 2013 8:14 pm

[QUOTE=zatyka]

It also needs to switch from one side to another like this ...

[N][N][ ][ ]
[N][ ][ ][N]


I'm not sure what is being switched in this example.
[/QUOTE]

(A)(B)( )( )
(B)( )( )(A)
B
38
S
16
G
17
Posts: 2,230
Reputation: 17,220

Post » Mon Apr 01, 2013 8:32 pm

[QUOTE=Whiteclaws](A)(B)( )( )
(B)( )( )(A)[/QUOTE]


B
55
S
17
G
8
Posts: 339
Reputation: 11,736

Post » Mon Apr 01, 2013 8:41 pm

@Zatyka , You forgot that it's a 2d array and I only want to move 1 row :)
B
38
S
16
G
17
Posts: 2,230
Reputation: 17,220

Post » Mon Apr 01, 2013 9:36 pm

@Whiteclaws
Sorry about that. Set ChangeY to the Y element you need to shift.

To shift the Y element left:


To shift the Y element right:
B
55
S
17
G
8
Posts: 339
Reputation: 11,736

Post » Mon Apr 01, 2013 9:38 pm

Thanks a lot , man !Whiteclaws2013-04-07 22:45:56
B
38
S
16
G
17
Posts: 2,230
Reputation: 17,220

Post » Sun Apr 07, 2013 10:46 pm

@zatyka , what about up and down ?

I'm sorry if i'm asking for too much but I'm feeling i've been in this issue issue for too long ...

Whiteclaws2013-04-07 23:01:09
B
38
S
16
G
17
Posts: 2,230
Reputation: 17,220

Post » Mon Apr 08, 2013 1:43 pm

Same principle as shifting a value along the X Axis:

ChangeX = Column to be shifted
Shift Up:

Shift Down:
B
55
S
17
G
8
Posts: 339
Reputation: 11,736

Post » Mon Apr 08, 2013 6:47 pm

Here's a capx with all directions covered. I'm using index manipulation and value permutation, not quite the same thing as zatyka but the end result is pratically the same !
B
58
S
23
G
22
Posts: 890
Reputation: 16,790

Next

Return to How do I....?

Who is online

Users browsing this forum: blaze ritter, jhjconstruct and 10 guests