Accurate 2d array iteration work with C2 List UI [capx]

Get help using Construct 2

Post » Sun Oct 15, 2017 2:52 pm

First of all, I would like to make the following work.

How do I iterate through my array in such a way that the C2 list displays values according to array’s rows? Like so:

List index 0: displays: array row 0.

In other words I want to get:
Index 0: arrayValueEntered1, arrayValueEntered2, arrayValueEntered3
Index 1: arrayValueEntered4, arrayValueEntered5, arrayValueEntered6
Index 2: arrayValueEntered7, arrayValueEntered8, arrayValueEntered9

Thus all values like in the array but separated by a comma.

The only working thing I could come up with was to iterate using “For each XY element” but it obviously does not do what I intended.
I tried to build a while loop since I do not know how many rows there will be and then I nested a for loop since I know that I will have three values in my array in its height. Unfortunately I cannot make it work.

Thus, can you either correct my looping to achieve the desired effect or add a proper way of iterating to achieve what I am aiming at?

My secondary question is related to my goal, which is the most accurate representation of the array in a visual way. I chose to use the list but even if the above works, which even now does not at the moment of writing, I still would not be able to precisely change the values, only whole rows. Would there be a more accurate user interface to manipulate the array in the file so that the user could choose particular values to change?

capx for correction below:

dropbox.com/s/24hvomvee446x2p/2d%20array%20Iteration.capx?dl=0
Last edited by Voytek on Mon Oct 16, 2017 5:46 pm, edited 1 time in total.
B
14
S
3
G
1
Posts: 57
Reputation: 1,422

Post » Sun Oct 15, 2017 3:12 pm

This is from another thread, but shows how to address the array with two for loops.
http://www.blackhornettechnologies.com/Construct2Stuff/2DarraySample.capx
ImageImageImage
B
72
S
22
G
290
Posts: 3,885
Reputation: 159,511

Post » Mon Oct 16, 2017 3:22 pm

Thank you.
It is somewhat helpful, however it still prints according to the pattern below
*
*
*
*
*
*
etc
Whereas, my array should be printed in the list like so:
*,*,*
*,*,*
*,*,*
In hardcode it would be something like:
List: add item: array.at(0,0)&”,”&array.at(0,1)&”,”&array.at(0,2) at index 0
add item: array.at(1,0)&”,”&array.at(1,1)&”,”&array.at(1,2) at index 1
etc

The question is, how to do it with a nested loop in C2?
It seems a printing pattern is required to display the array like the pattern below but shorter:
https://www.youtube.com/watch?v=5LzcfT2_3_E

I still cannot get it in C2
B
14
S
3
G
1
Posts: 57
Reputation: 1,422

Post » Mon Oct 16, 2017 3:30 pm

The nesting is clearly defined. You loop in Y, then X. Or reverse them for the other direction.
http://www.blackhornettechnologies.com/Construct2Stuff/voytek_2DarraySample.capx
ImageImageImage
B
72
S
22
G
290
Posts: 3,885
Reputation: 159,511

Post » Mon Oct 16, 2017 5:39 pm

The pattern i am looking for to display in Construct 2 List, not in a text object, would look like this following your [blackhornet's] example:

List in Construct 2:
0: 0,5,10,15,20,25,30,35,40,45
1: 1,6,11,16,21,26,31,36,41,46
2: 2,7,12,17,22,27,32,37,42,47

which appears to be the visual representation of the array from Construct 2 debugMode. In other words, the list contains array rows and their indexes should match, which allows a removal of an entire row both from the list and array by means of array pop. Besides the List in C2 does not work the same as the text object.

dropbox.com/s/dts3h6hqum4emyn/voytek_2darraySample.capx?dl=0
B
14
S
3
G
1
Posts: 57
Reputation: 1,422

Post » Mon Oct 16, 2017 8:09 pm

B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

Post » Tue Oct 17, 2017 12:13 am

That is exactly what I have been trying to do! Beautiful result korbaach! You are super great! Thanks for letting me learn something new!

I also assume that there is no other way of representing the array graphically so that the horizontal values could be manipulated from the GUI instead of this one, where “horizontal values” are “frozen” in the list and are not clickable but still the user can delete an entire row and has a sense of what is going on, isn’t there?
B
14
S
3
G
1
Posts: 57
Reputation: 1,422

Post » Tue Oct 17, 2017 6:05 am

only in two steps..

Image

array1List1.capx
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

Post » Tue Oct 17, 2017 1:08 pm

I would not even think to do it in such a way, that is remarkable!
B
14
S
3
G
1
Posts: 57
Reputation: 1,422


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests