# Basic Array problem help

Get help using Construct 2

### » Sat Jan 05, 2013 4:17 pm

Hey

I am trying to loop through all my sprites (mushrooms) from top to bottom and store the current angle in an array. This will end up being a 10 x 10 grid of mushrooms, but for now just 1 column.

After its stored its angle I want to rotate it i.e. jiggle them about. It's kind of working but the data is incorrect (click the Donkey to download the JSON)

File is here - https://www.dropbox.com/s/p1qpuc2e4xjke5p/Mushroom.capx

All the angles should be 0,0,0,0 for this to be right.

Any ideas what I am doing wrong?
B
7
S
1
G
1
Posts: 25
Reputation: 701

### » Sat Jan 05, 2013 5:35 pm

Here you go..

https://dl.dropbox.com/u/666574/curv%20-%20mushrooms.capx

If you need anything explaining, let me know.
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

### » Sat Jan 05, 2013 6:13 pm

Actually, looking at your original capx, I think it might be better to explain where you were going wrong.

Events 2 and 3..

What's actually happening is, you're looping through each element in the array, THEN looping through each mushroom (by X ascending - should be Y).

Here's what's basically happening in your loops..

array index = 0
mushroom = first, set the array (0) to this mushroom angle
mushroom = second, set the array (0) to this mushroom angle
mushroom = third, set the array (0) to this mushroom angle
mushroom = fourth, set the array (0) to this mushroom angle
^ array (0) = fourth mushroom's angle

array index = 1
mushroom = first, set the array (1) to this mushroom angle
mushroom = second, set the array (1) to this mushroom angle
mushroom = third, set the array (1) to this mushroom angle
mushroom = fourth, set the array (1) to this mushroom angle
^ array (1) = fourth mushroom's angle

and so on for all 4 array elements. All array values will be the fourth mushroom's angle.

Also, event 5, you're testing the value at array index 0 with the current mushroom angle which would be wrong anyway. Each mushroom has to point to the correct array index, hence the arrayIdx in my capx.

If you only wanted to check for angle 0 on every mushroom, then you wouldn't even need an array, but since you'll need to be checking for different angles, you need the array. I'm assuming this is a learning messabout before you implement it in your pipe game?
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

### » Sat Jan 05, 2013 6:35 pm

Thanks Pro will check it out. Yes pipe stuff :)

it's weird because in C# i could do this quite quickly but using the Construct visual way has melted my brain a little!

thanks again, sure i will ask another question later haha!

p.s. How do you guys debug in construct?curv2013-01-05 18:36:18
B
7
S
1
G
1
Posts: 25
Reputation: 701

### » Sat Jan 05, 2013 6:46 pm

I'm also from a programming background, and sometimes I find it hard to visualise things in the Construct way too. So you're not alone ;p

Yep, any questions or problems, ask away. I'm here most of the night so I'll help if I can.

edit> just spotted your debugging question.. I always use text boxes and such.procrastinator2013-01-05 18:49:49
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

### » Sat Jan 05, 2013 7:09 pm

Ok cool thanks pro
B
7
S
1
G
1
Posts: 25
Reputation: 701

### » Sat Jan 05, 2013 7:55 pm

No probs. Just remember to put all your debugging events into a group, so you can enable and disable at will.
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

### » Sat Jan 05, 2013 9:29 pm

Any ideas that when I set the angle of an object to 90 degrees it actually renders as 90.0002104591497 meaning the angle check will never work... This is not an issue as they are programatically rotated but just noticed it and wondered.
B
7
S
1
G
1
Posts: 25
Reputation: 701

### » Sat Jan 05, 2013 9:36 pm

I used Floor() anyway btw
B
7
S
1
G
1
Posts: 25
Reputation: 701

### » Sat Jan 05, 2013 9:47 pm

Not sure why it renders as 90.xxxxxx though. Just tried it here and it shows 90.
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

Next