# arrays and the mistery behind them

Get help using Construct 2

### » Sun Feb 12, 2012 4:55 pm

I followed the tutorials and I know what an array is in other languages, but I don't understand how they work in c2.
I'm posting the c2 code and my interpretation about how should they work in js.

Array set size to (3,0,0) //array[0] = false;array[1]=false;array[2]=false;

Array set value at 0 50 //array[0] = 50;
Array set value at 1 120 //array[1] = 120;
Array set value at 2 260 //array[2] = 260;

Create Object Circle on layer 1 at (array.At(0),0)
//I expect to create object circle at 50,0 but it's not working why is that?

Thanks
B
30
S
9
G
6
Posts: 525
Reputation: 8,329

### » Sun Feb 12, 2012 5:05 pm

In the example you posted here, you first initialie your array with boolean values and then override them with integers....is that intended?

it could be, that you receive a string which holds "50" when you do a "at(X)" so you have to cast it to an integer. you could do a "int(x)" to do thatWeishaupt2012-02-12 17:07:31
B
44
S
24
G
13
Posts: 723
Reputation: 15,105

### » Sun Feb 12, 2012 5:10 pm

Try set size to (3,1,1) rather, it should work.

Also, you may need to cast the result of an array to make sure it is a number.
So set X to int(Array.at(0)). (like weishaupt suspects)

New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
311
S
128
G
100
Posts: 7,413
Reputation: 74,722

### » Sun Feb 12, 2012 5:16 pm

I set the size to 3,1,1 but it still won't work. @Weishaupt the bool thing wasn't intentional it was my interpretation of what construct2 may do under the hood.
B
30
S
9
G
6
Posts: 525
Reputation: 8,329

### » Sun Feb 12, 2012 5:21 pm

A quick test that positions the sprite according to values stored in the array : quick test.

As long as the array is created in the same layout as you currently are, it should work.

If you have like two layouts, and that array was created in layout2 and you're trying to use it in layout1 it will not work.
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
311
S
128
G
100
Posts: 7,413
Reputation: 74,722

### » Sun Feb 12, 2012 5:27 pm

Uhmm seeing your example I see that in my c2 in the properties of the array I don't have width height and depth..

Is it a bug?
B
30
S
9
G
6
Posts: 525
Reputation: 8,329

### » Sun Feb 12, 2012 6:16 pm

Sounds like you created the array in a layout that was then deleted, or something like that.

It is more or less a known bug yes. (Has to do with the fact that you need at least one instance of an object type in the project for it to work).

Make a new array, set the code to work with it and then destroy the old array.Kyatric2012-02-12 18:17:27
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
311
S
128
G
100
Posts: 7,413
Reputation: 74,722

### » Sun Feb 12, 2012 6:24 pm

Problem is that any array I create has the same problem.. please tell me there is a fix I don't want to start from scratch..
B
30
S
9
G
6
Posts: 525
Reputation: 8,329

### » Sun Feb 12, 2012 8:48 pm

send the capx
B
71
S
22
G
14
Posts: 1,494
Reputation: 16,660

### » Sun Feb 12, 2012 11:07 pm

I would prefer not to since it's an almost finished game, is it ok if I strip everything out leaving just the array logic?
B
30
S
9
G
6
Posts: 525
Reputation: 8,329

Next