How to insert itens to an array (easy way)

Get help using Construct 3!

Post » Sun Jun 04, 2017 8:40 am

Hello guys,
I'm using arrays on my project but I'm not sure if I'm doing it wrong or it's the only way..
For example, each item that I need to insert I have to set:
X,Y,Z and the value.
I need to fill a line with 20 itens, is there any way to do it like:
1,Z,1, values: 1,2,3,4,5 ?

Cheers mates
"Hello my friend stay a while and listen"
B
62
S
33
G
27
Posts: 81
Reputation: 18,628

Post » Mon Jun 05, 2017 2:28 pm

You can use a "for" loop to fill an array:

For name: "i", start: 0, end: array.width-1 | Set array.At(loopindex("i"),0,0) to loopindex("i")

This will set each (X,0,0) to the current loopindex of the "for" loop i.e. (0,0,0) (1,0,0) (2,0,0)...

You can modify this for the other dimensions:

For name: "i", start: 0, end: array.height-1 | Set array.At(0,loopindex("i"),0) to loopindex("i")
For name: "i", start: 0, end: array.depth-1 | Set array.At(0,0,loopindex("i")) to loopindex("i")

You can also use nested "for"loops to set multiple rows, e.g.:

For name: "i", start: 0, end: array.width-1 |
>>For name: "j", start: 0, end: array.height-1 | Set array.At(loopindex("i"),loopindex("j"),0) to loopindex("i")+loopindex("j")

If you are planning on adding a lot of data to an array you can create a array.json text file and import that into your array object using the AJAX object. This tutorial helps explain:

https://www.scirra.com/tutorials/1303/h ... nal-arrays
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Tue Jun 06, 2017 6:29 am

mekonbekon wrote:You can use a "for" loop to fill an array


Thank you for the reply but as the numbers are not sequential I think that is impossible to do.
Using for it will fill with a fixed variable that increments each loop time.
Look what I have to do to fill:
Image
I'm populating 2 arrays, my project is an infinity jump game, so, each platform have different sizes and forms, sometimes you can't have the same platform or a platform with the same "design".
The first array is just to know which platforms can be created after the current one, it is random from this array in the column which the current platform is. It is working good.
The second one is just to know the space between the current and the new one and is also working good.
I'm just trying to find an easy way to do it.
I have about 15 platforms...
This image is just for one.
;)
"Hello my friend stay a while and listen"
B
62
S
33
G
27
Posts: 81
Reputation: 18,628

Post » Tue Jun 06, 2017 7:49 am

@klabundee

Ah, ok. In that case, I'd use the json and AJAX method - it'll be a lot quicker to create the arrays that way than setting up the data using individual actions.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Tue Jun 06, 2017 8:00 am

Just realised we're in the C3 forum! You can use the built-in array editor to add data to the array:

In the project bar, scroll down to the files icon, right click, select "New" and then "Array": this will automatically create an array.json.
If you right click on this file and select "edit", the array editor will open and you can add the data directly.
I think you will still need to import that data into an actual array object using the AJAX method linked above.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Tue Jun 06, 2017 8:53 am

Oh, sorry, my bad posting here, it should be C2.
But thanks anyway.
"Hello my friend stay a while and listen"
B
62
S
33
G
27
Posts: 81
Reputation: 18,628

Post » Tue Jun 06, 2017 10:07 am

mekonbekon wrote:Just realised we're in the C3 forum! You can use the built-in array editor to add data to the array:

In the project bar, scroll down to the files icon, right click, select "New" and then "Array": this will automatically create an array.json.
If you right click on this file and select "edit", the array editor will open and you can add the data directly.
I think you will still need to import that data into an actual array object using the AJAX method linked above.


Well, just bought a C3 license, so yeah, I'm using this way ;)
Thanks!!
"Hello my friend stay a while and listen"
B
62
S
33
G
27
Posts: 81
Reputation: 18,628

Post » Tue Jun 06, 2017 10:30 am

Would be good if C3 doesn't have a bug with it....
:evil:

If add a new array file and change the array size... it's enough to crash it and ask to restart.
"Hello my friend stay a while and listen"
B
62
S
33
G
27
Posts: 81
Reputation: 18,628

Post » Tue Jun 06, 2017 10:48 am

Oh dear...

If you can replicate the bug I'd report it. As a workaround you can download the array json file, edit it in a text editor and then add it back into the project - that should get around any bugs in the array editor.
B
20
S
8
G
3
Posts: 458
Reputation: 4,055

Post » Tue Jun 06, 2017 10:51 am

mekonbekon wrote:Oh dear...

If you can replicate the bug I'd report it. As a workaround you can download the array json file, edit it in a text editor and then add it back into the project - that should get around any bugs in the array editor.


Just did, https://github.com/Scirra/Construct-3-bugs/issues/451
If you have C3, can you try to see if happens there?
Cheers
"Hello my friend stay a while and listen"
B
62
S
33
G
27
Posts: 81
Reputation: 18,628

Next

Return to How do I...?

Who is online

Users browsing this forum: No registered users and 0 guests