ScriptCraft

ScriptCraft

14.6k Downloads

methods that use exports do not work the same as those that use drone.extend

kellyfj opened this issue ยท 2 comments

commented

ENVIRONMENT
Jars

CanaryMod-1.8.0-1.2.0-RC1.jar

and ScriptCraft.jar from http://scriptcraftjs.org/download/latest/scriptcraft-3.1.10/

$ java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: OS X 10.10.5 (14F27)
      Kernel Version: Darwin 14.5.0

Two functions with the same code inside

var house1 = function() {


    this.box(blocks.cobblestone,5,1,10);
    this.up(1);
    this.box0(blocks.cobblestone,5,6,10);
    this.up(6);
    this.prism(blocks.glowstone,5,10);

    return;
};
var Drone = require('../drone/drone').Drone;
Drone.extend('house1',house1);

versus

exports.house1a = function() {


    this.box(blocks.cobblestone,5,1,10);
    this.up(1);
    this.box0(blocks.cobblestone,5,6,10);
    this.up(6);
    this.prism(blocks.glowstone,5,10);

    return;
}

House on the left is from the drone.extend version, house on the right uses exports

2015-11-20_07 59 09

Looks like this variant does work though

exports.house1b = function() {


    this.box(blocks.cobblestone,5,1,10)
    .up(1)
    .box0(blocks.cobblestone,5,6,10)
    .up(6)
    .prism(blocks.glowstone,5,10);

    return;
};

But shouldn't this.doX().doY() be equivalent to

this.doX();
this.doY();
commented

Drone.extend and exports are not the same thing.
exports is modeled on the commonjs (nodejs) public/private module mechanism.
Drone.extend is for adding new methods to the Drone (and also publishes such methods as global functions).

The this keyword inside the context of a module will refer to the global object, while the this keyword inside the context of a Drone.extend function will refer to the Drone.

commented

OK Thanks!