[C3 ONLY] JS Based generalization of the Eleanor trick

4

Stats

1,548 visits, 2,594 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. Last updated 4 Sep, 2019

As I said, the Eleanor trick is very specific, and might not work for everyone. Thankfully, C3 has had a few new features that arrived since that trick was discovered. Namely Javascript.

Slow down

I will not tell you to write your code in JS, DO NOT WORRY. But still, JS has some pretty neat features you might wanna know about.

JS allows you to use super fast, compiled to assembly, for loops. Doesn't get much faster than this.

JS allows you to get the currently picked instances of a given object type.

JS allows you to call a built-in function (and potentially get its return value)

The whole point of the Eleanor trick is to trick the expression engine into doing the for each loop for us in Javascript. But what if we do it ourselves?

const instanceArr = runtime.objects.MyObject.getPickedInstances();

for (let i = 0; i < instanceArr.length; i++) {
    const inst = instanceArr[i];
    runtime.callFunction("MyFunction", inst.uid [,inst.instVars.param1, localVars.param2, ...]);
}

If you pick the objects you want to run over, and instead of doing a for each loop, you do this, you'll get the same perf as the Eleanor trick, but without the requirement for the function to return a value, and without the need to use expression fields.

That means that you should be able to use this instead of any For Each Instance loop.

Though, right here I'm not doing much in terms of optimizing. I'm only skipping the SOL updating part.

While you're using JS, you should probably make your condition checking, or make the big processing stuff right here directly instead of porting it all to functions.

Next Tutorial In Course

Mix it up 00:24

Little bit o' both.

  • 0 Comments

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