ScriptCraft

ScriptCraft

14.6k Downloads

Exports object doesn't seem to be working

patredmond opened this issue ยท 3 comments

commented

I've downloaded CanaryMod and scriptcraft from here: http://scriptcraftjs.org/download/latest/
I can connect to the server and basic commands work (eg '/js 2 + 3').

When I try to run a function via the 'exports' object as directed on p63 of "A Beginner's Guide to Writing Minecraft Plugins in Javascript" it fails giving the exception:

"Error while trying to evaluate javascript: greet(self), Error: javax.script.ScriptException: ReferenceError: "greet" is not defined in at the line number 1 in at line number 630 at column number 8".

The numbers vary, however the message is essentially the same for every function I try to run.

image

commented

OK, I think I've figured this out. The book says you need to use this code:
exports.helloWorld = helloWorld();

however, this doesn't seem to work at all. Instead this code works:
exports.helloWorld = function helloWorld() {...

commented

Thank you Walter! I appreciate your support.

commented

Hi @patredmond ,

On page 63 listing 5.3, the last statement is

exports.helloWorld = helloWorld;

This exports a reference to the helloWorld function whereas if you wrote:

exports.helloWorld = helloWorld();

this would invoke helloWorld() and export the return value (undefined).