Meaning of "Sub-events"

Discussion and feedback on Construct 2

Post » Thu Feb 07, 2013 12:03 am

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
            
B
5
S
1
Posts: 39
Reputation: 703

Post » Thu Feb 07, 2013 12:20 am

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.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Thu Feb 07, 2013 1:19 am

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

Thankssammyconstruct2013-02-07 01:21:30
B
5
S
1
Posts: 39
Reputation: 703

Post » Thu Feb 07, 2013 11:59 am

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.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Feb 07, 2013 2:13 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Thu Feb 07, 2013 8:33 pm

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.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973


Return to Construct 2 General

Who is online

Users browsing this forum: humanescape and 10 guests