Arrays in expressions

Get help using Construct 2

Post » Fri Dec 02, 2011 10:38 pm

Is there a way to fill up an Array directly in one expression

Like this in c:

int Array[6][3]={100,250,150,25,25,25,250,25,25,75,150,100,25,50,150,50,100,25};

It would be faster then creating events for each array position.
B
14
S
5
G
5
Posts: 8
Reputation: 3,601

Post » Fri Dec 02, 2011 10:40 pm

I meant an *action for each array position
B
14
S
5
G
5
Posts: 8
Reputation: 3,601

Post » Sat Dec 03, 2011 7:44 pm

You can do it with a comma separated string of text and the "tokenat" expression.

+Start of Layout
-- Array | Set size to (6,3,1)
---- + Array | For each XY element
------ Array | Set value at (Array.CurX, Array.CurY) to tokenat("100,250,150,25,25,25,250,25,25,75,150,100,25,50,150,50,100,25", Array.CurX +Array.CurY*Array.Width, ",")
B
89
S
30
G
95
Posts: 5,157
Reputation: 63,450

Post » Sat Dec 03, 2011 9:07 pm

Not as far as I know
For something like that I tend to use a string and parse its token.

like
Code: Select all
list = "2
5
4
3
1"

for "parse" from 0 to tokenCount(list,newline)
    -> Array: set tokenat(list,loopindex("parse"),newline) at loopindex("parse")


(damn r0j0's too fast :D)
Last edited by Yann on Sun Sep 14, 2014 12:13 pm, edited 1 time in total.
B
64
S
22
G
14
Posts: 1,482
Reputation: 16,457

Post » Sun Dec 04, 2011 5:55 am

Thank you guys!
B
14
S
5
G
5
Posts: 8
Reputation: 3,601

Post » Thu Jul 19, 2012 10:38 pm

Bugger!

This is excactly what I need, but I don't get @R0J0hound 's solution..

I just wan't to fill a 1D array with 10 names..
B
5
S
1
Posts: 43
Reputation: 1,002

Post » Thu Jul 19, 2012 10:57 pm

@engberg: Does it help if you see it in action?

Quick .capx: Fill1DArray.capx (r99)

If you wonder how the tokenat expression works, have a look at this manual entry. If you need more info on arrays, I would recommend this tutorial.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Thu Jul 19, 2012 10:58 pm

Yann's answer is a pretty close interpretation to how to implement it in C2.

Tokenat et tokencount are both system expressions.

Implementation example.

As this is an old topic, now you could also use the "load as JSon" action, as explained in the array manual entry.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
276
S
103
G
84
Posts: 7,289
Reputation: 83,098

Post » Fri Jul 20, 2012 3:12 pm

@Nimtrix Your capx really helped me - thanx..

@Kyatric - I think I might use JSon in a later project - good stuff!
B
5
S
1
Posts: 43
Reputation: 1,002

Post » Tue Jul 24, 2012 8:19 am

AsJSON Rocks!
B
14
S
5
G
5
Posts: 8
Reputation: 3,601

Next

Return to How do I....?

Who is online

Users browsing this forum: Aenopix and 2 guests