#why is my script not working
44 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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.
// 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
} ```
how much of this is 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.
true
Dam😔 i don’t got time to learn js because of school is there anything in #1048591172165189632 like this?
i cant even figure out what its trying to do
like it doesnt even resemble KJS scripts
:(
??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.
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
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
How would I do that?
at the top of a js file, you use //requires: modname if i recall correctly
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!')
ye
That’s all????😱
yeeee that file will only be loaded if that mod is loaded
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
if the pack wont load, kubejs cant load either, which means the scripts also dont
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
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
It works ty guys