Nested For loops and a 3rd condition - User Error?

This forum is currently in read-only mode.
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • I'm writing a tutorial on building random dungeons (per the recent discussions by others), using Construct to create the tutorial itself.

    I aim to have the start of the tutorial go through the concepts of random dungeons through click-next pages, and then to have the program create and build a random dungeon to demonstrate the process.

    The tutorial will also be in the form of a cap file, documented to help understand how it works.

    What's this got to do with the title of the thread?

    Well, I have the dungeon creation part sorted, but I'm having trouble with using more than 2 Conditions in an Event.

    Here's a pic of what I have.

    <img src="">

    What I'm trying to do is to have the Event go through the nested X and Y loops, checking the contents of the Array at position (x,y,1), and if the contents are what I expect them to be, to act on it in the Event line.

    I'm still trying to fathom out some of Constructs logic flow, so I was hoping you could tell me whether the pic above should work or not.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes, that should work. You can see the looping conditions indent slightly to show the nesting. You could also test it yourself by making the line add something like x,y to a listbox and see the output you get.

    You can also nest with subevents - but generally I prefer the look of same-event nested loops like in your picture.

  • If you are using the Array object, couldn't you use the "for each element" condition?

  • Yeah, I tried listboxes earlier on today, as well as a few other tried and tested bug-finding methods, but none of them shed any light on what the problem could be.

    Apart from it maybe being a bug in Construct, the only other thing that I could think of was that maybe the cap I'm working on has become corrupt somehow, so I thought I'd start a new cap with just an array, a listbox, and a few commands.

    <img src="">

    Now unless I'm missing something on setting up the Array, surely that should fill the listbox up with the word "yes".

    I'll upload this test cap to the upload area in a second, just so you can try it.

    I haven't had a look at the "for each element" yet.

    I'm trying to keep the coding as simple as possible so that non-coders can understand the tutorial better.

  • Unfortunately it seems that you have stumbled upon a bug with Array - Compare value at X,Y,Z.

    Use Array - Compare value at X,Y or X instead. Also, as shown in the example I uploaded in your upload thread, "For each element" Array condition removes the need for the loops.

  • That character after 'Yes' looks like a ^ rather than a ". Is it (a) a display bug, (b) intentionally typed, or (c) a typo?

    Probably has absolutely nothing to do with your problem, but I just thought I'd mention it

  • Thanks guys.


    So it was a bug then.

    That drove me nuts for a good hour or so before I knew it couldn't be me.

    And this 0-indexed / 1-indexed issue needs sorting.

    I've used 0-inexed arrays for years, but I'm quite happy to use 1-indexed arrays if we have to, as long as it's clearly marked as such, and that the build is actually using what they say.

    Thanks for the example using "for each element" too.

    That's a much cleaner way of doing things.

    EDIT: Looking again at your example, it checks the value of z, rather than the the contents of the array at z, and I thought that I might suffer the same problem with the array when trying to read the contents.

    But luckily, using something like "Array(Array.CurrentX, Array.CurrentY, 3)" does read the contents of Z..........BUT....... appears that the arrays are using both 0-indexing and 1-indexing. One for reading and one for writing.

    For instance, if you set array(10,10,5) to 1, when you check the array for a stored 1, it will find it at array(9,9,4).


    It's a display bug in Construct, although you did have me wondering.

    When edited in Construct, it shows a quote each side of the letter, and when committed, it displays that odd character again.


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