#why is my script not working

44 messages · Page 1 of 1 (latest)

woeful basin
#

keep in mind i do not know java script i looked around to try to make it

tough ravenBOT
#

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

tawny kilnBOT
#

Paste version of startup.log from @woeful basin

#

🗒️**Send the code!**🗒️
You may have an issue with a KubeJS script and you explain it to the best of your ability yet without the actual code in question we have very little to go off of in trying to assist you.

woeful basin
#
   // priority: 0

// Visit the wiki for more info - https://kubejs.com/

// Import kube.js modules
const { Events } = require('@kube.js/core');
const fs = require('fs');
const path = require('path');

// Define the path to the mods folder
const modsFolderPath = '/Wilderness Odessy/mods';

// Define the details of the required mod
const requiredModName = 'wilderness_oddesy_api';
const requiredModVersion = '2.3.0';

// Subscribe to the pre-init event
Events.on('pre-init', async () => {
    // Check if the required mod with the correct version is present
    const isModPresent = await isModInstalled(requiredModName, requiredModVersion);

    // If the required mod with the correct version is not present, prevent the modpack from starting
    if (!isModPresent) {
        console.error(`ERROR: The required mod "${requiredModName}" version "${requiredModVersion}" is not installed.`);
        process.exit(1);
    }
});

// Function to check if a mod with a specific version is installed
async function isModInstalled(modName, modVersion) {
    try {
        // Read the contents of the mods folder
        const files = await fs.promises.readdir(modsFolderPath);
        
        // Check if the required mod is present in the mods folder
        const modFile = files.find(file => file.startsWith(modName));
        if (!modFile) {
            return false;
        }

        // Get the version of the mod
        const modFilePath = path.join(modsFolderPath, modFile);
        const modManifest = await readModManifest(modFilePath);
        const modFileVersion = modManifest.version;

        // Check if the version of the mod matches the required version
        return modFileVersion === modVersion;
    } catch (error) {
        console.error('Error checking mod version:', error);
        return false;
    }
}

// Function to read the mod's manifest file to get its version
async function readModManifest(modFilePath) {
    try {
        const manifestFilePath = `META-INF/mods.toml`;
        const manifestFileContent = await fs.promises.readFile(path.join(modFilePath, manifestFilePath), 'utf-8');
        const manifest = parseToml(manifestFileContent);
        return manifest.mods[0];
    } catch (error) {
        console.error('Error reading mod manifest:', error);
        return null;
    }
}

// Function to parse TOML format
function parseToml(tomlString) {
    // Implement your TOML parser here, or use an existing library
    // For simplicity, assuming it's implemented elsewhere
}  ```
meager vessel
#

how much of this is AI

woeful turret
#

yes.

#

??ai

tawny kilnBOT
# woeful turret ??ai

NEVER use any AI to generate KubeJS code. They currently know very little about it, and what they do know is often outdated or false. You can instead look at the KubeJS wiki or ask for help in #1047320998199955458.

meager vessel
#

precisely 120% of this code is wrong

#

not a single letter is correct

woeful turret
#

raha true

uneven citrus
#

so that's why i was confuse

#

more cuz i'm dumb but that's why

meager vessel
#

this is genuinely the worst ive seen AI do xD

#

when it comes to attempting kjs

woeful basin
meager vessel
#

i cant even figure out what its trying to do

#

like it doesnt even resemble KJS scripts

#

:(

woeful turret
#

??helpyou

tawny kilnBOT
# woeful turret ??helpyou

╰( ͡° ͜ʖ ͡° )つ──☆:・゚˜”°•.˜”°• Many Help •°”˜.•°”˜*
Please provide a description of your issue with as much detail as possible. If you have an issue with a script provide the script. Explain what you can see happening and what you expect to happen. Be specific!

Tell us what is happening, we already know it "doesn't work".
Avoid using words like "it", tell us exactly what "it" is.
Don't assume anyone knows what you are talking about, be specific.

Provide screenshots or video of the issue if possible.

Provide the log.

woeful basin
#

So i wanted the script to detect a mod but if the script does not detect that mod or version the modpack will fail to start

meager vessel
#

detecting if a mod is loaded is just 1 line of code, i dont know how to get its version though

#

actually you dont even need code for that

#

just a comment

woeful basin
#

How would I do that?

meager vessel
#

at the top of a js file, you use //requires: modname if i recall correctly

tawny kilnBOT
#

In 1.19.2 you can use various headers at the top of a script to change its load conditions.
For example:

//ignored: true
console.log("I am never printed")
//packmode: default
console.log('I will only print when packmode in kubejs/config/common.properties is set to default')
//requires: minecraft
//requires: create
console.log('I will only print when mods with ids of minecraft AND create are loaded')

You can stack these too, like so

//priority: 10
//packmode: hard
//requires: create
//requires: tconstruct
console.log('I am complicated!')
meager vessel
#

ye

meager vessel
#

yeeee that file will only be loaded if that mod is loaded

woeful basin
#

I mean my modpack tho like if it does not detect a mod in the modpack it will fail to load

#

Or is that what you said

meager vessel
#

if the pack wont load, kubejs cant load either, which means the scripts also dont

woeful basin
#

Oh

#

Also another question so I wanted evry time someone create a new world I wanted a command to be run ( set seasons LATE_WINTER) how would I do that

#

Or is that in the wiki

meager vessel
#

there was something on that, its a simple thing, let me find it

#
ServerEvents.loaded(e => {
  if (e.server.persistentData.firstLoad) return
  e.server.persistentData.firstLoad = true
  e.server.runCommandSilent('write your command here')
})
#

something like that

woeful basin
#

Ok

#

I will see if it works

woeful basin
#

It works ty guys