How do I cycle through values in an array?

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi

    So I am storing items in an array and want the user to be able to cycle through by either clicking left or right. I am testing if the next value in the array is equal to 1 and, if so, setting a global variable to that y value. If not, it should skip to the next value in the array and test that, so on until we either find one with a 1 or get to the end of the array.

    While I can cycle through objects no issue if the next in the array is 1, and can stop if the next is 0, I'm having all sorts of trouble skipping 0 values and testing the next one in line.

    I believe I need to use a for loop here and use a testing variable to find the next available space, but to be honest, I'm struggling a bit with Construct's logic with this one. I've included a sample file to show what I have so far:

    Also a pic of my event sheet so far:


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • okay, I tried using a while loop and, after crashing C3 completely a couple of times and losing my work, * I think * it works.

    Can anyone with a bit more experience than me please just run your eyes over this and let me know if there's anything majorly wrong with it? I feel like while loops are kind of like trying to defuse a bomb... :/

  • in the array you can do a "for each element" instead of using the system for each or system while loop

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