Is there any quick way to add multiple values to an array?

0 favourites
  • 6 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi, guys

    I want to add more value to the array, but it is not intuitive when I used this way

    Is there any quick way to add multiple values to an array?

    Thank you!

  • You can use a loop to populate the values of an array. However, if your values do not have a logical relation to each other, that may be difficult

  • You can use a loop to populate the values of an array. However, if your values do not have a logical relation to each other, that may be difficult

    My values do not have a logical relation to each other, so I can't use a loop.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm, I feel like there's probably a way to cycle through a preset pattern of numbers but I can't think of it. You can potentially use variables to set values through events, I'm just wondering if there's a way to streamline it more than what I have in mind.

    Basically something like,

    Level=1 + Variable1<=5 --> Set Array value [Variable1] to [Variable2] + Add 1 to Variable1 + Run Function "Z"

    Level=2 + Variable1<=11 --> Set Array value [Variable1] to [Variable2] + Add 1 to Variable1 + Run Function "Z"

    On Function "Z"

    [sub-event] If Variable2 = 2 --> Set Variable2 to 5

    [sub-event] If Variable2 = 5 --> Set Variable2 to 9

    [sub-event] If Variable2 = 9 --> Set Variable2 to 13

    etc.

    So if Level=1, it'll run through Array values 0 to 5 using Variable1 as the index, and assign the value of Variable2 to each, where Variable2 is responsible for keeping track of the pattern. If Level=2 it does the same for values 0-11. I think this ought to work.

  • You could use text with a loop.

    Repeat 10 times:

    --- array: push tokenat("4,66,33,31,1,0,5,7,8,8", loopindex,",") to end

  • You could use text with a loop.

    Repeat 10 times:

    --- array: push tokenat("4,66,33,31,1,0,5,7,8,8", loopindex,",") to end

    Thank you, its work like charm

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