#KubeJS utility functions

17 messages · Page 1 of 1 (latest)

cinder drift
#

any way to import utility functions from a file in the KubeJS directory? I've tried import 'util' and import('util') (where util is a module at kubejs/util.js) but knowing JS there's probably some other way I'm forgetting. The log keeps saying import is a reserve word

simple heraldBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

rustic hamlet
#

you dont need to use import, all files in each folder types are loaded into one global scope

#

by folder type i mean startup/server/client

cinder drift
#

ah ok

#

so I could just put a util.js in startup scripts then,

#

?

rustic hamlet
#

if you want to use it in your startup scripts, yes

cinder drift
#

ok so I would need one for each folder type then

#

that's fine

#

does load order matter? wait I could just use hoisting

rustic hamlet
#

you can make it fully global

#

but for that you should put the util file in startup, and assign each function/variable that you want to use outside of it, to global

#

so instead of function doSomething(), you do global.doSomething = () => {}

cinder drift
#

ah ok

rustic hamlet
#

the global variable is an object that works across all scripts

cinder drift
#

thanks!