Lib.EternaScript fails due to bad data access

Did a little bit of digging, and there’s a very small issue causing Lib.EternaScript() to fail. The script is acquired with the following code:

data = Script.get\_script\_sync(id); script = data['script'][0];

However, if you look at the API’s response for a script (like this one), everything is contained under the "data’ object, so either the first line should be

data = Script.get\_script\_sync(id)['data'];

or the second line should be

script = data['data']['script'][0];

I’d assume the first one would be optimal.

1 Like

Which is why I tend to use a “private trick” in my scripts:

    Library.prototype.EternaScriptFunction = function(id) {
      var code, data, i, inputs, input, script, \_i;
      data = Script.get\_script\_sync(id).data;
      script = data['script'][0];
      code = "";
      if (script['input']) {
        inputs = JSON.parse(script['input']);
&nbsp; &nbsp; &nbsp; &nbsp; for (i = \_i = 0; \_i \< inputs.length; i = ++\_i) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input = inputs[i];
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; code += "var " + input.value + "=arguments[" + i + "];";
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; code = "Lib = new Library();" + code + script['source'];
&nbsp; &nbsp; &nbsp; return new Function(code);
&nbsp; &nbsp; };

 // now use like this: var f = Lib.EternaScriptFunction(3378282);
 // then call, passing parameters
 var result = f(x, y);

I never got around to make that addition to the “standard” library though. Since you’re raising the issue, there’s now officially more than one guy (me) who’s bothered by the fact, so I conclude that we now have a good enough reason to bother Jnicol/Caleb with it :slight_smile:

Will keep you posted.

I remember seeing you post that, and had issues with it for some reason, no clue why. Going back and trying it again though it does work like a charm. Such a little fix though, I’d like to see this work without the substitution as it’s pretty useful. Thanks!

Caleb seems to have pushed a patch minutes ago, using one of your proposed fixes. @LFP6: does it work now as you expect?

Yep, works like a charm. Thanks!