ScriptCraft icon indicating copy to clipboard operation
ScriptCraft copied to clipboard

drone location not being passed to functions?

Open Rob-bb opened this issue 11 years ago • 2 comments

Hi

I have written a few functions that extend the drone class to build some things. I have broken the task down to the separate functions and am now trying to string them together in a build function.

Each function works fine when called from within mc via /js but when called from a function they fail.

using this code here: this.chkpt('build_start_pos'); console.log(this); for (var h = 0; h < height; h++) { gv_pillars(p_blk, p_meta); this.up(10); console.log(this); } g_vault(v_blk, v_meta); this.move('build_start_pos');

I get this output in the console:

rob_bb issued server command: /js build_gv(24,1, 98,2 , 5) [scriptcraft] x: 128 y: 4 z: 381 dir: 1 south [scriptcraft] x: 128 y: 14 z: 381 dir: 1 south [scriptcraft] x: 128 y: 24 z: 381 dir: 1 south [scriptcraft] x: 128 y: 34 z: 381 dir: 1 south [scriptcraft] x: 128 y: 44 z: 381 dir: 1 south [scriptcraft] x: 128 y: 54 z: 381 dir: 1 south

but the objects in mc are not where I would expect, instead of 4 corners based on start position, drawn 5 times going up the z axis I get one single pillar.

so in the gv_pillars function I added console.log(this); and I am gettign this output:

rob_bb issued server command: /js build_gv(24,1, 98,2 , 5) [scriptcraft] x: 120 y: 3 z: 374 dir: 0 east [scriptcraft] [object Global] [scriptcraft] x: 120 y: 13 z: 374 dir: 0 east [scriptcraft] [object Global] [scriptcraft] x: 120 y: 23 z: 374 dir: 0 east [scriptcraft] [object Global] [scriptcraft] x: 120 y: 33 z: 374 dir: 0 east [scriptcraft] [object Global] [scriptcraft] x: 120 y: 43 z: 374 dir: 0 east [scriptcraft] [object Global] [scriptcraft] x: 120 y: 53 z: 374 dir: 0 east

What does [object Global] mean, and why is the drone appearing to stand still rather than move?

here is the complete code.

cheers.

// // Functions to create pasages. //

var utils = require('utils'); var blocks = require('blocks'); var Drone = require('../drone/drone').Drone;

function build_gv(v_blk, v_meta, p_blk, p_meta, height){ if (typeof p_blk === "undefined") { p_blk = v_blk; } if (typeof p_meta === "undefined") { p_meta = v_meta; } if (typeof height === "undefined") { height = 1; } this.chkpt('build_start_pos'); console.log(this); for (var h = 0; h < height; h++) { gv_pillars(p_blk, p_meta); this.up(10); console.log(this); } g_vault(v_blk, v_meta); this.move('build_start_pos');

} Drone.extend( build_gv );

function gv_pillars(pillar_block, pillar_meta){ // // Creates pillars for a groin vault ceiling 16x16 blocks (one chunk) //

if (typeof pillar_meta === "undefined") {
    pillar_meta = 0;
}

this.chkpt('pillars_start_pos');
console.log(this);
var blk = pillar_block.toString() + ":" + pillar_meta.toString();

this.left(2).up(1);
// first clear the space with air blocks
this.box(blocks.air, 16, 9, 16);
this.down(1);
// make the pillars, they start one block under ground
this.box(blk, 2, 10, 2);
this.fwd(15).turn(1);
this.box(blk, 2, 10, 2);
this.fwd(15).turn(1);
this.box(blk, 2, 10, 2);
this.fwd(15).turn(1);
this.box(blk, 2, 10, 2);
this.fwd(15).turn(1);

this.move('pillars_start_pos');

} Drone.extend( gv_pillars );

function g_vault(vault_block, vault_meta){ // // Creates a groin vault ceiling 16x16 blocks (one chunk) // starting 6 blocks above the block the player // is looking at. //

if (typeof vault_meta === "undefined") {
    vault_meta = 0;
}

this.chkpt('vault_start_pos');

// first clear the space with air blocks
this.left(2).up(10);
this.box(blocks.air, 16, 8, 16);

// set the main positions
this.move('vault_start_pos');
this.up(4);
this.chkpt('gv_pos1');
this.left(2).fwd(13).turn(1);
this.chkpt('gv_pos2');


// now build the groin vault
this.move('gv_pos1');
this.arc({blockType: vault_block, 
       meta: vault_meta, 
       radius: 6,
       strokeWidth: 1,
       quadrants: { topleft: true},
       orientation: 'vertical', 
       stack: 16,
       fill: false
       } );
this.left(1)
this.arc({blockType: vault_block, 
       meta: vault_meta, 
       radius: 6,
       strokeWidth: 1,
       quadrants: { topright: true},
       orientation: 'vertical', 
       stack: 16,
       fill: false
       } ); 
this.move('gv_pos2');  
this.arc({blockType: vault_block, 
       meta: vault_meta, 
       radius: 6,
       strokeWidth: 1,
       quadrants: { topleft: true},
       orientation: 'vertical', 
       stack: 16,
       fill: false
       } );
this.left(1)
this.arc({blockType: vault_block, 
       meta: vault_meta, 
       radius: 6,
       strokeWidth: 1,
       quadrants: { topright: true},
       orientation: 'vertical', 
       stack: 16,
       fill: false
       } );     

// Now fill with air to clear out the arches       
this.move('gv_pos1');
this.right(1);
this.arc({blockType: blocks.air, 
       meta: 0, 
       radius: 5,
       strokeWidth: 5,
       quadrants: { topleft: true},
       orientation: 'vertical', 
       stack: 16,
       fill: false
       } );
this.left(1)
this.arc({blockType: blocks.air, 
       meta: 0, 
       radius: 5,
       strokeWidth: 5,
       quadrants: { topright: true},
       orientation: 'vertical', 
       stack: 16,
       fill: false
       } );     
this.move('gv_pos2');
this.right(1);  
this.arc({blockType: blocks.air, 
       meta: 0, 
       radius: 5,
       strokeWidth: 5,
       quadrants: { topleft: true},
       orientation: 'vertical', 
       stack: 16,
       fill: false
       } );
this.left(1)
this.arc({blockType: blocks.air, 
       meta: 0, 
       radius: 5,
       strokeWidth: 5,
       quadrants: { topright: true},
       orientation: 'vertical', 
       stack: 16,
       fill: false
       } );         

} Drone.extend( g_vault );

Rob-bb avatar Sep 21 '14 02:09 Rob-bb

I currently have a work around where I am passing 'this' to the functions as shown bellow

this.chkpt('build_start_pos');
console.log(this);
for (var h = 0; h < height; h++) {
    gv_pillars(p_blk, p_meta, this);
    this.up(10);
    console.log(this);
}
this.down(10);  // g_vault is desgined for a height of 1
g_vault(v_blk, v_meta, this);
this.move('build_start_pos');

} Drone.extend( build_gv );

function gv_pillars(pillar_block, pillar_meta, drone){

if (typeof pillar_meta === "undefined") {
    pillar_meta = 0;
}
if (typeof drone === "undefined") {
    drone = this;
}
  drone.chkpt('pillars_start_pos');

Rob-bb avatar Sep 21 '14 03:09 Rob-bb

Hi Rob, You can also create a new Drone() object by passing it a Location object.

walterhiggins avatar Sep 21 '14 12:09 walterhiggins