How do I Make a condition that applies for ALL INSTANCES

Get help using Construct 2

Post » Tue May 23, 2017 11:16 pm

How do I Make a condition that applies for ALL INSTANCES of an Object? Say that there are like, 24 instances of the same object. I want something to happen when all of those instances are a similar animation frame. Can anyone help? :|
B
6
Posts: 3
Reputation: 256

Post » Wed May 24, 2017 12:14 am

You can use a loop (system command) "For each [object]"

For each Object
--- Object.value = XYZ
------------> Do stuff

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
80
S
34
G
40
Posts: 3,029
Reputation: 30,393

Post » Wed May 24, 2017 12:46 am

Or you could put the animation-frame condition and as a sub-condition, pick all objects of that kind (System condition -> Pick all) and then execute the action at that sub-condition.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Wed May 24, 2017 4:18 pm

You simply need to add a "compare two values" under you other conditions with something like this.
Code: Select all
Object.PickedCount = Object.Count

The event will run only if all instances satisfy whatever conditions you want.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Wed May 24, 2017 6:56 pm

@Magistross

I believe that @LunchboxGames wants the events that come after the compare condition to apply to all objects.

So he wants an action to apply to all objects when a specific condition is met.
The problem that he states is thought that a condition never picks the objects to which the condition doesn't apply, thus, all following actions usually don't work for all objects, but only those that meet the condition.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Wed May 24, 2017 7:31 pm

Well if I take his example of animation frame, he wants an event that will check if all 24 instances have the same one, then do something to those 24 instances. My previous example will do just that. However, if he wants actions that affect all instances no matter how many instances were picked previously, a simple "pick all" will work wonder.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Wed May 24, 2017 8:16 pm

Magistross wrote:
Code: Select all
Object.PickedCount = Object.Count


So this condition picks all the objects again?
Doesn't it work so that the first condition eliminates all objects out of the PickedList that don't meet the condition and the next condition works with that new PickedList?
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Wed May 24, 2017 8:22 pm

The goal is a condition that is true on ALL instances. Which means a PickedCount (filtered SOL) equals to Count (unfiltered SOL).
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Fri May 26, 2017 6:11 am

I'm trying to get a separate object to do something while every instance of another object is either one or the other animation frame (so, say that the object can be either animation frame 3 or 9 to trigger the action)
B
6
Posts: 3
Reputation: 256

Post » Fri May 26, 2017 7:50 am

Use a sub-sub or a function.

A function starts picking from scratch. (so, including ever instance again)

A sub-sub will not change the parent picklist.

Sprite > Compare frame <--- pick all with a certain frame = Parent Picklist
System > compare 2 values .. Sprite.Count = Sprite.PickedCount
______Just an empty sub event
________sub under that empty event ... System > Pick All (Sprite) <------ this is the Sub Picklist / Parent is unchanged when returning to parent level
______________action : do your stuff

Thing is now, be careful with this 'PickedCount'. If you wanna do something when none of them have this frame .... Then the 'Sprite.Count = Sprite.PickedCount' will not ever run. Not as sub, not as second in a parent.

So just to be complete ...

Sprite > Compare frame
System > compare 2 values .. Sprite.Count = Sprite.PickedCount
______Just an empty sub event
________sub under that empty event ... System > Pick All (Sprite)
______________action : do your stuff
Else
_____Actions to take care of the exception where the first event will not run.


Additional. Testing for an animation frame has a dangerous side.
Say, the animation speed = 20 and it runs at 60 FPS. Then each frame will be there for 3 ticks. (when the animations sync up)
As a result this condition (above) will be true for 3 ticks in a row.

Usually you solve this with a 'System > Trigger once while true'.

Sprite > Compare frame
System > compare 2 values .. Sprite.Count = Sprite.PickedCount
System > Trigger once while true

'Trigger once while true' runs its event once when the paired up condition(s) are true. Then it sits there, and waits. Until the conditions are not true, then it flags its event as executable again.

But that will not be flawless in the above conditions because of the above explained exception.
When there i no Sprite with that frame, the condition will not run, the 'Trigger once while true' will also not run.
As a result it miss out the change in true/untrue for the next tick.

There is also the possibility of an additional 'thing'. Say, the animations do not run in sync. Then 'this tick' a certain sprite changed frame, while another one is still in the same frame.

Comes down to this. When Sprite.Count is equal to Sprite.PickedCount this tick it can only run its actions when Sprite.Count was not equal to Sprite.PickedCount in the previous tick.

Using a Global Variable.


Sprite > Compare frame
_____Sub / System > compare 2 values .. Sprite.Count = Sprite.PickedCount
___________Sub / GlobalVariable = zero ?
_________________sub / System > Pick All (Sprite)
_______________________action : do your stuff
___________Sub / Empty event
_________________action : set GlobalVariable to 1

_____Else
__________action : set GlobalVariable to 0
Else
_____ if it is needed to capture the exeption
B
33
S
18
G
27
Posts: 2,440
Reputation: 20,344

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests