Nashorn has trouble casting JS arrays to native java arrays when invoking vararg methods.
I'm calling a Java method from JS. The java method uses variable arguments...
In my JS I construct an array variable and populate the array:
/*global require, events */ | |
var blocks = require('blocks'), | |
sounds = require('sounds'); | |
function bounceOn___(event){ | |
var player = event.player; | |
var bounce = 0.75; | |
var location = player.location; | |
// need to convert coordinates to integers | |
var x = Math.floor(location.x); |
var Drone = require('drone'); | |
var blocks = require('blocks'); | |
function skyscraper( floors ) { | |
var i = 0; | |
if ( typeof floors == 'undefined' ) { | |
floors = 10; | |
} | |
this.chkpt('skyscraper'); | |
for ( i = 0; i < floors; i++ ) { | |
this |
var sounds = require('sounds'); | |
function howl(event){ | |
sounds.wolfHowl(event.block); | |
} | |
events.blockDestroy(howl); |
var teleport = require('teleport'), | |
arrowsport = {}, | |
handler; | |
function onArrowHit( event ) { | |
var projectile = event.projectile, | |
shooter = projectile.owner, | |
cmArrow = Packages.net.canarymod.api.entity.Arrow, | |
cmPlayer = Packages.net.canarymod.api.entity.living.humanoid.Player, |
Nashorn has trouble casting JS arrays to native java arrays when invoking vararg methods.
I'm calling a Java method from JS. The java method uses variable arguments...
In my JS I construct an array variable and populate the array:
This is list of errors and their corrections that were found after the book was published. This document is a work in progress. If you find additional mistakes in the book please email walter.higgins@gmail.com.
The following code is listed with no explanation of the ===
operator and how it differs from the ==
operator which is explained in Chapter 3 (Comparing numbers):
/* | |
testing a forgetful memoized promise: A promise, memoized which is forgotten after a given duration. | |
*/ | |
var Q = require('q'); | |
var _ = require('underscore'); | |
function expensive( req ){ | |
var result = Q.defer(); | |
var msg = JSON.stringify(req); | |
console.log(new Date() + ' about to do something expensive: ' + msg); |
There were some very good ideas for improvements and additions. One attendee wondered if it was possible to populate buildings as they were built. I thought I'd already written a spawn module to do this but it turns out I hadn't. I've just added a spawn module to version 3.1.11 which is out today (21st Nov 2015). Get it here http://scriptcraftjs.org/download/latest/
The Drone now also has a spawn method so you can for example unleash a horde of zombies by combining the spawn()
, movement and times()
functions like this...
/js spawn('ZOMBIE').fwd().times(10)
var lightning = require('lightning'); | |
events.projectileHit( function(event) { | |
if ( entities.arrow( event.projectile ) && | |
entities.player( event.projectile.owner ) ) { | |
lightning( event.projectile ); | |
} | |
} |