How do I properly pick family instances?

Get help using Construct 2

Post » Fri May 09, 2014 8:51 am

What is there to explain? In that event, 'Mouse: on any click' has no effect on the picking at all. It doesn't matter what conditions are above it, you'd always need a for-each loop to push back an array item for each instance.
Scirra Founder
B
398
S
236
G
88
Posts: 24,441
Reputation: 194,661

Post » Thu Jun 19, 2014 2:56 pm

Thank you @Ashley for you answer. I am sorry to respond this late, but I did not see your response before (it landed as a first post on the second page, so I somehow did not registered it).

Well, the mouse condition is irrelevant in this example. It is what follows that I find puzzling for users. At least for me, since i did not understand it and had problems even after reading relevant manual pages and the official blog text about gotchas. Take a look at the following example, please

Image

The set opacity action works fine (as expected), that is, for each worker. On the other hand, the function does not get executed for each worker. The function in question simply sets the opacity of worker identified with the UID to 50. It is a simple wrapper function for the build-in set opacity action. And yet, it gets executed only once, for the first instance of the worker object. As I see it, it is so, because a function is a single instance object. Every function objects gets picked and since there is only one function object, function gets executed only once.

I agree that it is a consistent Construct 2 behavior. However, I think that it is not properly documented behavior. Or at least, it should be pointed to as a gotcha. Maybe it is something obvious to you why you should put system condition "for each" in front of function calls and it is redundant to do it before build-in actions. However, I highly doubt that it is for other users which did not participate in the development of C2.
B
6
S
2
Posts: 64
Reputation: 576

Post » Thu Jun 19, 2014 3:37 pm

I think you have a slight confusion about how actions work. Actions run only once per event, but they run across all objects of that action's 'object type' that were picked by the event conditions. Your event picks all workers which are overlapping the selection box, but only picks one instance of the function object (because there is only one) so it only runs the call function action once, because call function is a function object action, not a worker action. It would be the equivalent of having the function call in a blank sub event, so that's why you need the foreach. It would be different if somehow objects could have functions as instance variables, because then you could call the function as a worker object action and skip the foreach

It's not so obscure as you may believe, you just need better understanding of the event system
B
6
S
2
Posts: 79
Reputation: 608

Post » Thu Jun 19, 2014 4:45 pm

Thank you monitz87. I think I finally got it now. This sentence,

"Actions run only once per event, but they run across all objects of that action's 'object type' that were picked by the event conditions."

was a a crucial part of your explanation.
B
6
S
2
Posts: 64
Reputation: 576

Previous

Return to How do I....?

Who is online

Users browsing this forum: Armench, Jackriduk, kiki4construct and 26 guests