Create JavaScript function and call ingame with /js

42 views
Skip to first unread message

heid...@hotmail.com

unread,
Sep 27, 2019, 9:08:16 AM9/27/19
to ScriptCraft - Scripting Minecraft

Hello everyone, 

as a complete newbie in JS and MC I wanted to create JS-functions which I can call using the /js command.
As a example I created "claims.js" with following content:

function getClaimCount(player)
{
 
return server.pluginManager.getPlugin('griefprevention').dataStore
 
.getPlayerData(player.getUniqueId())
 
.getClaims().size();
}


How would I call this method? I tried /js getClaimCount(self) but with no success....


Mike Stay

unread,
Sep 27, 2019, 1:01:36 PM9/27/19
to ScriptCraft - Scripting Minecraft

heid...@hotmail.com

unread,
Sep 28, 2019, 6:53:47 AM9/28/19
to ScriptCraft - Scripting Minecraft
Ah, don't know how I missed that... export is working. Thank you very much!

And if I'd like to call a method from a different JS-File, do I need to export those functions as well?
I tried it like this:

require('./claims.js');



export.claims = function ClaimCount(player) {
return getClaimsCount(player); //function in claims.js
}


but it tells me that "claims" does not exist.
Message has been deleted

heid...@hotmail.com

unread,
Sep 28, 2019, 7:28:39 AM9/28/19
to ScriptCraft - Scripting Minecraft
Stupid me ^^ 
Yes it has to.
Reply all
Reply to author
Forward
0 new messages