[C3 ONLY] The Eleanor trick

4

Stats

1,950 visits, 2,608 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 29 Aug, 2019.

The Eleanor trick (or the Eleanor) is a trick first discovered and explained by Eleanor: construct.net/en/forum/construct-3/general-discussion-7/eleanors-patreon-the-best-142183

She used it for her game Strawberry Punch, and has decided to widely share it so we can also have good perf in our games.

In case you don't want to read through her super long and detailed explanation, here is what you need to understand:

New C3 Functions are fast

New C3 Expressions are fast

C3 For each loops are slow. Because they're still the same as before.

Thus if you manage to write your heavy for each code inside a function that takes a UID as a parameter and use the expressions to loop through every instances, you get better results.

Concrete use case

Eleanor needed to compute the X, Y, Z position of her players at every frame (and thus couldn't use the tickcount trick. To get the 3D coordinates she needed to loop through every player and make some pretty big calculations. This was slow.

Instead what she did was divide the calculation into subfunctions that take a player UID and returns the right coordinate for that player. She then used expressions to make boolean checks and pick what function to use for any given character. Construct then does its magic and loops that compiled to JS expression over every instance, and it's much more efficient.

The drawbacks

This still has pretty specific use cases, and requires the function to return a value in order for it to be used inside an expression field. That expression field must be inside an action from the targeted object type and should only refer to that object type for the for loop to properly execute (i.e. for Construct to understand that it needs to run that action once for each picked instance).

Thankfully using the new JS features, we can use that trick and generalize it.

Next Tutorial In Course

[C3 ONLY] JS Based generalization of the Eleanor trick 01:28

Javascript? JAVASCRIPT? JAVASCRIIIIIIIIIIIPT!!!?!??!

  • 0 Comments

Want to leave a comment? Login or Register an account!