arrays and the mistery behind them

Get help using Construct 2

Post » 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
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » 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
42
S
19
G
12
Posts: 723
Reputation: 13,911

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

Some leads that will hopefuly help you.Kyatric2012-02-12 17:11:24
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » 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
29
S
9
G
6
Posts: 525
Reputation: 8,294

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

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » 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
29
S
9
G
6
Posts: 525
Reputation: 8,294

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

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » 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
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sun Feb 12, 2012 8:48 pm

send the capx
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » 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
29
S
9
G
6
Posts: 525
Reputation: 8,294

Next

Return to How do I....?

Who is online

Users browsing this forum: Kagubro and 19 guests