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

Get help using Construct 2

Post » 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
Image

Is there any quick way to add multiple values to an array?
Thank you!
B
34
S
16
G
18
Posts: 58
Reputation: 11,710

Post » 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
28
S
10
G
10
Posts: 97
Reputation: 6,584

Post » 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
34
S
16
G
18
Posts: 58
Reputation: 11,710

Post » 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
50
S
23
G
17
Posts: 291
Reputation: 12,432

Post » 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
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » 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 :D
B
34
S
16
G
18
Posts: 58
Reputation: 11,710


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Shenkai the ssj and 24 guests