#AddJson() replacement
75 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
ummm how did you use it
/**
* Removes advancement at given file-path and adds it to a hidden parent advancement
* @param {String | Array} advancementFilePath - Where the advancement file is located. Can easily be found through /advancement command or GitHub
*/
function removeAdvancement(advancementFilePath) {
let arr = []
if (typeof (advancementFilePath) == 'string') arr = [advancementFilePath]
else if (typeof (advancementFilePath) == 'object') arr = advancementFilePath
else console.log(`Invalid type for removeAdvancement(${advancementFilePath})`)
ServerEvents.loaded(event => {
arr.forEach(advancement => {
event.addJson(`${advancement}.json`, {
parent: 'minecraft:advancements/root',
display: { hidden: true },
criteria: {
impossible: {
trigger: 'minecraft:impossible'
}
},
requirements: [['impossible']]
})
})
})
}
removeAdvancement([
'create:advancements/root',
'create:root',
'create:advancements/andesite_alloy'
])
My current full code, i assumed AddJson just doesn't exist for that event or something
ingame error
This is a list of all the events. Choose your version.
i was about to say that 
im also surprised the event is picked up inside the top level function 
makes me think about redoing scripts 
events are just functions themseleves
kinda
in hindsight i should have seen that, looking at the code i thought it was more so that the event fired when the server started but its not that weird that i can't edit datapack stuff without using datapack events
yeah but i thought the top function is being executed when the script is loaded, which in most cases is way before the event fires
but i guess it just caches the event somewhere and runs it later

ye thats what im saying
kubejs executes the scrilt once when its loadef
ye
well, guess thats another issue solved within seconds of posting it. next time i should probably triple check everything, should i close the thread or wait until you're done talking lol
but the event isnt a thing until way after the top function is executed
we can always close it again
we'll close it :p
yes, and the top function is executed when the scriot is loaded
which is instant
not when the event fires
i would write a debug script but im at work and i cant

its like how
function foo() {
console.log('hi')
}
foo()
still logs hi immediately
the event handler is still 'caught' cause it was added when the script was loaded and run for the first time
ye but i dont think you understand what im saying 
what if you have the recipes event
or item rightclick event
neither of those are run anytime near when the top function is
hmm i just had a thought
you pass a function (the event => {} bit ) to an event (ie ServerEvents.loaded), that function is what gets stored to run later
whats this gonna do? can you test it?
let test = () => {
console.log(1)
ServerEvents.loaded(_ => console.log(2))
console.log(3)
}
test()
that wont do anything
w0t
cause you never call the test function
it would log
1
3
2
so it does cache it for later
yes, it stores the function you pass to the event to run for later
the _ => console.log(2) bit
let test = () => {
let list = [1]
console.log(list)
ServerEvents.loaded(_ => {
list.push(2)
console.log(list)
})
list.push(3)
console.log(list)
}
would that print
[1]
[1, 3]
[1, 2]
not quite
the last one would be```js
[1, 3, 2]
yes. the function stores its context which includes all of the variables currently in scope
cool cool 
theoretically you may even be able to call test() from the event
Джава always confuses me sometimes with copies and references lol
wouldnt that make it recursive

no
wha-
because you cant add event handlers after the initial load
oh
and the loaded event would only be called once anyway
so it would just run everything except the event part inside it
yeah
right
as you wish

