Basic Array problem help

0 favourites
  • 10 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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 - 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?

  • Here you go..

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

    If you need anything explaining, let me know.

  • 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?

  • 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?

  • 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.

  • Ok cool thanks pro

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • No probs. Just remember to put all your debugging events into a group, so you can enable and disable at will.

  • 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.

  • I used Floor() anyway btw

  • Not sure why it renders as 90.xxxxxx though. Just tried it here and it shows 90.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)