How do I fill an array with for.. ? [quick][newbie]

Get help using Construct 2

Post » Tue Jan 03, 2017 8:38 pm

Hi guys, I've blocked on something, very stupid, i think, i got a problem with arrays.
I tried to fill an array like this

[declaring int i = 1 ]
system -> for (i) from 0 to 100 => Array value at (i) to 9999.

i've tried to add action (add 1 to 'i' ) but it goes to -> infinity (it doesn't stopped at 100 )

So, if I would like to fill an array (x-axis) with 9 with an for how should i do it ?

** YES, YES, i've red the 'loop' tutorials, thank you.
*** Can i somehow use the for and fill it with a variable without using another variable to 'scroll' the array ?
Thanks
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Tue Jan 03, 2017 8:46 pm

Image
ImageImageImage
B
71
S
21
G
231
Posts: 3,691
Reputation: 129,358

Post » Tue Jan 03, 2017 8:52 pm

If the array is 1 dimensional ...

Array > for each element ... element = x
.... Array > set at X .... X = Array.CurX .. value = whatever you like

If the array is 2 dimensional ...

Array > for each element ... element = x
.... Array > set at XY .... X = Array.CurX .. Y = an index you want to store something on ... value = whatever you like
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Jan 03, 2017 10:17 pm

@blackhornet :| Thank you for showing me the 'loopindex', I apreciate that.
@99Instances2Go Thank you mate !
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Tue Jan 03, 2017 10:45 pm

To use your own name, set your Name to "i", then use loopindex("i") to address it.
Last edited by blackhornet on Wed Jan 04, 2017 3:30 pm, edited 1 time in total.
ImageImageImage
B
71
S
21
G
231
Posts: 3,691
Reputation: 129,358

Post » Wed Jan 04, 2017 12:06 am

Wel, to be clear, i prefer the 'for' loop.
Although maybe (i dont know, but thinking to understanding Ashley a little) the 'for each element' might be more optimised.

Additional.
If you want to run trough each element with a 'for', the start is zero, the end is array.width - 1 (for the x-axes)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Jan 04, 2017 1:09 pm

@blackhornet Yep, Thanks

@99Instances2Go I understant, again thank you.

Thank you guys !
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Wed Jan 04, 2017 1:32 pm

@blackhornet loopindex("i") doesn't work, sorry
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Wed Jan 04, 2017 3:29 pm

Image
ImageImageImage
B
71
S
21
G
231
Posts: 3,691
Reputation: 129,358


Return to How do I....?

Who is online

Users browsing this forum: David181, FacuLNF and 46 guests