Question about picking instances C2 R47-2

Discussion and feedback on Construct 2

Post » Tue Jul 12, 2011 5:36 pm

[QUOTE=Ashley] You still seem a little confused about how these events work. Most of your events are redundant. I made some changes, try this project. You're just trying to match a Color object with a random frame for each Runnerz, right?

Remember ordinary events have a for-each built in to them. The event:

Every tick
-> Set runner X to runner.X + 1

is run by C2 like this:

Every tick
-> For each runner instance: set X to self.X + 1

See there's no need for a 'for each' condition - 'every tick' does the job fine.

Conditions also have a built in for each. The event:

Runner: X < 400
-> Set runner X to runner.X + 1

is actually run by C2 like this:

For each runner: if X < 400, remember this instance
-> For each remembered instance (all of the ones with X < 400): set X to Self.X + 1

You only ever need 'For each' when this built-in behavior isn't enough. One of those rare situations is when you're using the "Compare values" condition, because it does not pick anything for you. For example:

+ Compare values: Runner.X < 400
-> Set runner X to runner.X + 1

C2 runs the event like this:

Evaluate Runner.X. I'll just grab the first one because I don't know which one to use. Is Runner.X < 400? Yes. (note no objects have been remembered)
-> For each runner instance: (I haven't remembered any, so I'll run on all of them) Set Runner X to Runner.X + 1

Despite the event, all the runners move right. You could add a for-each to fix it - but it would be better just to use the "Compare X" condition!

Finally, to pair up objects, a neat trick is just to use

Every tick
-> Set colour position to (runner.X, runner.Y)

This pairs each colour with a runner. This is because C2 runs the event like this:

Every tick
-> For each colour instance: find a runner object paired with me. Now set my position to that X and Y.

This doesn't work with the 'set position to object' action! That's a bug, I'll see if I can fix for the next build.

In short, C2 is trying to do for-eaches and pairing everywhere for you. You just need to know how it works under the hood to take advantage. Hopefully the .capx above helps!

The containers system in Classic also fixes this issue, because it forces instance pairing. Destroying the objects is a bit of a hack in my example, but I guess it works. I'll add unique IDs (UIDs) for the next build - that enables another workaround.[/QUOTE]

Wow, C2 is even more powerful than I thought.
Ashley you got it all covered. I will need to read this a couple more times, but this explanation + the capx should do the trick.
That's what I needed, an update to the way C2 works.

Thanks for the enlightment. :)

EDIT: @Magistross:
Does not work for you ?
Direct link to the executable (hoping it is not messing with Tom's site)Kyatric2011-07-12 17:38:45
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Posts: 7,083
Reputation: 62,882

Post » Tue Jul 12, 2011 5:47 pm

That's weird, the page for the r47.2 release has the following download link on my end :

Your direct link works just fine though !

edit : It's fine now, I erased all my cache. The site was behaving very strangely too, don't know why the files weren't getting updated correctly in the cache...
Magistross2011-07-12 17:51:03
Posts: 870
Reputation: 15,448

Post » Tue Jul 12, 2011 5:51 pm

Link whatever pages you want, don't worry about it! We want to get as many people downloading it as possible so feel free to distribute the direct link anywhere you want.
Image Image
Scirra Founder
Posts: 4,080
Reputation: 47,235

Post » Tue Jul 12, 2011 6:06 pm

Tom regularly tweaks the site and I think recently fixed a bug in the latest release page, so there might be a few hiccups.
Scirra Founder
Posts: 23,262
Reputation: 183,679


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 1 guest