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

Get help using Construct 2

### » Tue Sep 20, 2016 2:46 am

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!
B
44
S
25
G
25
Posts: 85
Reputation: 16,424

### » Tue Sep 20, 2016 3:15 am

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
B
29
S
10
G
10
Posts: 97
Reputation: 6,614

### » Tue Sep 20, 2016 3:28 am

makotto wrote: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.
B
44
S
25
G
25
Posts: 85
Reputation: 16,424

### » Tue Sep 20, 2016 3:34 am

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.
B
62
S
25
G
19
Posts: 306
Reputation: 13,964

### » Tue Sep 20, 2016 4:06 am

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
B
100
S
38
G
134
Posts: 5,552
Reputation: 85,317

### » Tue Sep 20, 2016 5:39 am

R0J0hound wrote: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
B
44
S
25
G
25
Posts: 85
Reputation: 16,424