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

For questions about using Classic.

Post » Sun Mar 01, 2009 10:08 pm

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.



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.

Cheers.
B
2
S
1
G
3
Posts: 105
Reputation: 1,310

Post » Sun Mar 01, 2009 10:19 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Mar 01, 2009 10:22 pm

If you are using the Array object, couldn't you use the "for each element" condition?
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Mon Mar 02, 2009 12:15 am

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.



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.
B
2
S
1
G
3
Posts: 105
Reputation: 1,310

Post » Mon Mar 02, 2009 8:56 am

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. ;)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Mon Mar 02, 2009 10:43 am

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 :)
B
2
S
2
G
3
Posts: 105
Reputation: 1,510

Post » Mon Mar 02, 2009 12:23 pm

Thanks guys.

@Mipey;
So it was a bug then.
That drove me nuts for a good hour or so before I knew it couldn't be me. :lol:

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

......it 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).



@GMG;
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.

Cheers.
B
2
S
1
G
3
Posts: 105
Reputation: 1,310


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests