How do I Make a condition that applies for ALL INSTANCES

0 favourites
  • 13 posts
From the Asset Store
Rpg action of Neves is a complete template to apply your story to create your world.
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You can use a loop (system command) "For each [object]"

    For each Object

    --- Object.value = XYZ

    ------------> Do stuff

    ~Sol

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

  • You simply need to add a "compare two values" under you other conditions with something like this.

    Object.PickedCount = Object.Count[/code:1qaha72s]
    The event will run only if all instances satisfy whatever conditions you want.
  • 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.

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

  • Object.PickedCount = Object.Count[/code:hx6ncj5q]
    

    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?

  • The goal is a condition that is true on ALL instances. Which means a PickedCount (filtered SOL) equals to Count (unfiltered SOL).

  • 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)

  • 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

  • But now i only checked only 1 frame. Guess i need to check a range of frames.

    Using an Array (size : how many frames , 1 , 1)

    An Array is just and no more then a way to organize variables that can have more values at the same time.

    System > For .. Name = "aFrame" ... Start = zero ... End = how many frames

    Sprite > Compare frame ... frame = loopindex("aFrame") ?

    _____Sub / System > compare 2 values .. Sprite.Count = Sprite.PickedCount

    ___________Sub / Array > Compare at X .... X = loopindex("aFrame") ... Value =? zero

    _________________sub / System > Pick All (Sprite)

    _______________________action : do your stuff

    ___________Sub / Empty event

    _________________action : Set at X ... X = loopindex("aFrame") ... Value = 1

    _____Else

    __________action : set Set at X ... X = loopindex("aFrame") ... Value = 0

    Else

    _____ if it is needed to capture the exeption

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

    Pick All does not work.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)