Difference in calling a function vs activating a group?

0 favourites
  • 8 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Is there a large difference in calling a Function vs Activating/Deactivating a group?

    The only difference I have noticed is one extra event where you have to deactivate a group. I actually only used groups without any issues before knowing of Functions.

    I may be using Functions wrong as well.

    It seems they are meant for single use only. As in spawning an object.

    Will using the same function constantly(non-stop) for something long term or possibly a loop cause issues? Possibly as in a timer that restarts when hitting 0, or controlling an animation frame based off of a variable?

    All of the Capx files I have downloaded used function or nothing at all. I haven't seen anybody activating/deactivating groups as I have. Am I missing something? Is there a difference in performance?

  • There are plenty of differences, and valid use cases for both.

    Functions are a mostly to minimize repetitive code. Things that you're going to be doing over and over, sometimes with maybe just a few variables. They are also triggers, which means they fire once and done. Using them in a loop should not cause problems and is common.

    Enabling/Disabling Groups can be used for a variety of things. Unlike a function, you can have non-triggered events running in a group. So that when a group is active, everything in it is running. This makes groups useful for turning off 'functions' (groups of events) that might be unnecessarily using up resources if they're running when they don't need to be (which, in my opinion, usually means your code could should probably be more effecient).

    Many people activate/deactivate groups though, I assure you. There's absolutely nothing wrong with that.

    Hope that helps!

  • In addition to what spacedoubt said:

    • You can pass a parameter to the function, which you cannot do for groups.
    • Toggling a group takes effect in the next tick while triggering a function takes effect in the same tick

    It is true that you can in most common cases use functions or groups and you will have the same effect. You can add "Trigger once" to the gorup and the code will run only once - like in a function. But it's not always replaceable and it's much about semantic to use both in a right way.

    Groups help you encapsulate your code and mainain the overall performance by smart toggling. Functions are more like helpers for common (for your project) actions.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From my understandings if a group is activated but not in use, it checks the main event and skips it's sub events.

    If a group is deactivated is it skipped on every tick or is the main event analyzed and ignored?

    What about Functions? is it skipped on ticks unless called or analyzed as well?

    I will most likely adopt Functions because it uses less events to call than to activate/deactivate a group and they seem like they act faster when called.

  • The main difference is how they are run: a function will call the "On function" event, run it to completion, and then return to the "call function" action and continue from there. In other words it calls other events from within an action.

    Activating a group just enables a bunch of events so that they can be read the next tick. It doesn't actually run anything at the point you say "activate group".

  • The main difference is how they are run: a function will call the "On function" event, run it to completion, and then return to the "call function" action and continue from there. In other words it calls other events from within an action.

    Activating a group just enables a bunch of events so that they can be read the next tick. It doesn't actually run anything at the point you say "activate group".

    Is it worth toggling groups to gain performance, or as I remember conditions that are not met just don't run?

  • Disabling groups can help improve performance, since all the events in the group must still test their conditions against (possibly many) instances to determine that nothing meets the condition. It can keep executing through to later conditions in the same event as well before it determines the event won't run. So disabling the event can save all that work from happening. Or, it might make no difference at all. As ever you should measure it to determine if it's worthwhile.

  • Disabling groups can help improve performance, since all the events in the group must still test their conditions against (possibly many) instances to determine that nothing meets the condition. It can keep executing through to later conditions in the same event as well before it determines the event won't run. So disabling the event can save all that work from happening. Or, it might make no difference at all. As ever you should measure it to determine if it's worthwhile.

    Thanks for the answer. Could I ask you one more question re this. What would be best way of toggling groups with single chain events like this one: For each Door, boo = 1? I'd think toggling based on distance, but that again would require to check all Door objects.

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