Iteration throught arrays not working

Get help using Construct 2

Post » Tue Jul 03, 2012 12:17 am

I'm new to Construct 2 and have been testing it for some days, to see what features it can provide to me.
Then, I was testing the arrays feature to create a rectangle with objects type, so later I can implement a random dungeon algorithm.
But then, I got a problem with it and although I have a background on programming and even OOP, couldn't figure out what is wrong.

Here are the screenshot of the Event Sheet:

My idea was to iterate over a bi-dimensional matrix where the values of each block doesn't matter, only the index of the iteration, since I can't put a For statement inside another.
And the layout, sheet and layer are correctly associated (leaved them to default, only changed the name).
And the object Walls have 32x32 size, but this is easily handled.

My question is: is there anything that I should've done first? Why it doesn't iterate the loop?

Link to project:
Posts: 16
Reputation: 1,033

Post » Tue Jul 03, 2012 1:01 am

No need to create the array at the beginning. It should already exist.
You can also set the size of it beforehand in the preferences over to the left.

Also unless you add a trigger for each xy, it will run every tick, constantly creating objects.

Check out some of the tutorials on sub events.

Other than that it should work. Current x* 32, current y *32 in a 20 x 30 grid should give you 640 width x 960 height layout tho.

Also, also, yes you can nest a for loop, again read up on sub events.newt2012-07-03 01:06:29
Image Image
Posts: 7,242
Reputation: 61,512

Post » Thu Jul 05, 2012 5:43 am

I've read the tutorials before, but I thought that loop iterated everything before going to the sub-events. Then I read that again and managed to work just fine!

It was happening that it wasn't creating the objects in the screen, leaving it all white. But now with a simple trigger and For Each statement, the objects appeared.

And guess that the array won't be necessary, by the way.

Thanks for your response!
I'm more excited about it now.
Posts: 16
Reputation: 1,033

Post » Thu Jul 05, 2012 2:20 pm

For a dungeon algo you better use the array. I did a cave algo a while ago, trying to be smart I only used sprites by filling the layout with them and then digging into but it's way slower.
Handling cols*rows sprite is slower than an array of cols*rows data because sprites are big objects
Posts: 1,479
Reputation: 16,336

Return to How do I....?

Who is online

Users browsing this forum: farfetchd83, lainshi, MrWhizm, nav, RazHarmy and 5 guests