#Create global constants (accessible for e.g. from client and server scripts)

15 messages · Page 1 of 1 (latest)

feral tulip
#

Hello, I want to create constants with KubeJS accessible from differents locations, for example client scripts and server scripts. Is there a way to do this? Thank you by advance 😄

noble nebulaBOT
#

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

fossil quail
#

use global and make sure you put it in startup and set the priority to highest at the top of the script

//priority: 1000

global.test = 'test'
#

actually i'm not sure you have to use global

feral tulip
#

I'm not sure to understand what are test?

fossil quail
#

putting //priority: number at the top of the script makes it prioritized. kubejs loads the file with the highest number priority first within a script folder

feral tulip
#

Actually, I have this:

startup_scripts/constants/ingots.js

// priority: 1000

global.REPLACED = {};
global.REPLACERS = {};

/* Some code to fill REPLACED and REPLACERS here */

client_scripts/hide.js

// priority: 0

onEvent("jei.hide.items", event => {
    for (const item of Object.values(REPLACED))
        for (const id of item)
            if (!Object.values(REPLACERS).includes(id)) {
                event.hide(id);
                console.info(`Hiding ${id}`);
            }
});

And in client.txt, this error: Error occurred while handling event 'jei.hide.items': ReferenceError: "REPLACED" is not defined.

fossil quail
feral tulip
#

oh okay

fossil quail
#

if (!Object.values(global.REPLACERS).includes(id)) {

feral tulip
#

Okay thank you very much 😄

noble nebulaBOT
#

@feral tulip Unresolved thread still hasn't been closed! If your question was answered, please close this post with </ticket close:1054771505520717835> command!

noble nebulaBOT
#

@feral tulip Unresolved thread still hasn't been closed! If your question was answered, please close this post with </ticket close:1054771505520717835> command!