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
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

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
44
S
13
G
7
Posts: 338
Reputation: 10,379

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
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

Post » Mon Apr 01, 2013 8:32 pm

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


B
44
S
13
G
7
Posts: 338
Reputation: 10,379

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
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

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
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Mon Apr 01, 2013 9:38 pm

Thanks a lot , man !Whiteclaws2013-04-07 22:45:56
B
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

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
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

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
44
S
13
G
7
Posts: 338
Reputation: 10,379

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
45
S
16
G
18
Posts: 845
Reputation: 13,673

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Braus, supreme676, Yahoo [Bot] and 7 guests