Meaning of "Sub-events"

0 favourites
  • 6 posts
  • Hi all,

    I read the manual about sub-events:

    On the other hand, sub-events (which appear indented) carry on from where its parent event left off. A sub-event will further filter the instances left over by the event that came before it. If an event has two sub-events, they both pick from the same set of instances the parent left - the second sub-event is not affected by the first. In other words, events at the same indentation level always pick from the same set of instances, and events at a lower indentation level are always working with the instances handed down from above.

    In programming, is it similar to multiple if-condition?

    ie.

    if condition A

       if condition B

    Thanks in advance

  • Yes, a sub event only is evaluated if it's parent event is true, so it would be similar to a nested If Then Else statement from most programming languages.

  • Hi theubie,

    I see.

    Which one is faster for multiple "and" condition?

    1. Adding multiple sub-event, or

    2. Adding multiple and condition (I remember there is short-circuit elimination for if statement in most programming.)

    Thanks

  • If there is a difference, it is small enough, trivial in comparison to other performance hogs. Unless you are trying to simulate a neural web or something.

    Just one thing to consider - the conditions loop through available instances every time they're run. If there are a LOT of instances, it may be better to filter them into categories, so only relevant sets are available to conditions. I sometimes do that when dealing with a huge amount of objects. Set conditions into sub-events where objects are pre-filtered already, so not to re-pick them again. No clue if that helps at all, it sure helps me organize them in my mind, though!

    Come to think of it, if this concerns you so much, why don't you test it? Two test capx, different methods in each, see performance impact when dealing with 1000, 10000 and even 100000 instances.

  • You should prefer adding multiple conditions to the same event, but not for performance: it tends to make your events a lot more readable. Anything not mentioned in performance tips is likely to have negligible effect on performance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It depends on your background, Ashley. As a programmer, I prefer to see some of the multiple conditions broken down into sub events, as I visualize it more like traditional if then else statements. It's that indent that makes it look right to me. ;P

    Dealt with too many languages that would throw an exception if you tried to read a property or value from a uninitialized or null variable, so it's so ingrained in me to check for the existence of something before I start manipulating it that it just feels wrong for me sometimes to load up conditions on the top level of an event.

    Old coding habits (and most of them are bad habits) die hard.

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