How to insert itens to an array (easy way)

0 favourites
  • 15 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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

  • 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

  • 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:

    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.

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh, sorry, my bad posting here, it should be C2.

    But thanks anyway.

  • 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!!

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

    If add a new array file and change the array size... it's enough to crash it and ask to restart.

  • 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.

  • 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

  • Just tried it myself and didn't have a problem creating a new 10x10 array file, editing and saving it. Have you tried replicating with a brand new project and seeing if it still occurs?

  • Just tried it myself and didn't have a problem creating a new 10x10 array file, editing and saving it. Have you tried replicating with a brand new project and seeing if it still occurs?

    Yes

    But will also try with Firefox.

  • But will also try with Firefox.

    is not supported yet.

  • Hey mekonbekon;

    Thank you for your help!

    The problem is that I use grammarly extension on Chrome... after disabled it, all worked fine.

  • klabundee

    Aha! You're very welcome - glad you managed to find a fix : )

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)