#Script No Worky 2.0, CTX with a vengeance!
134 messages · Page 1 of 1 (latest)
@sharp mica
StartupEvents.registry('item', event => {
event.create('uncooked_dorito')
.displayName('§c§l§o§nUncooked Dorito')
.tooltip('§bNot very tasty, perhaps bake it?')
.food(food => {
food
.effect('minecraft:hunger', 1, 255, 1)
.eaten(ctx => {
ctx
.player.tell(Text.gold('Are you insane!?'))
})
})
})
when you open a ticket you must provide the script along with logs if its erroring
I did and there are no errors
in the original post 
Paste version of startup.log from @fickle agate
its ok
Paste version of client.log from @fickle agate
Paste version of latest.log from @fickle agate

StartupEvents.registry('item', event => {
event.create('uncooked_dorito')
.displayName('§c§l§o§nUncooked Dorito')
.tooltip('§bNot very tasty, perhaps bake it?')
.food(food => {
food
.effect('minecraft:hunger', 1, 255, 1)
.eaten(ctx => global.food(ctx))
})
})
global.food = ctx => {
const {player} = ctx;
if (!player.level.isClientSide()) return
player.tell(Text.gold('Are you insane!?'))
}```
@sharp micaI will try that script in a minute. Here is proof of the hunger thing not working(this is after bumping it to two tick)

the main things i changed are putting it into a global event so you can do /kubejs reload startup_scripts without having to reload the game and adding js if (!player.level().isClientSide()) return so the player tell only fires on the client side
why not just give them a flat hunger effect for like 15 seconds?
of like hunger 3
I want it to be hunger for a one minute as the given effect tbf. Honestly, might as well treat it like a golden apple but it's effect is hunger

that'd be what? 16.6 ticks correct?
Or something
@sharp mica Uhhhh
It's stuck on dispatching CONSTRUCT
I'ma try loading again if still stuck I will get log

I-
I fixed it?
StartupEvents.registry('item', event => {
event.create('uncooked_dorito')
.displayName('§c§l§o§nUncooked Dorito')
.tooltip('§bNot very tasty, perhaps bake it?')
.food(food => {
food
.effect('minecraft:hunger', 600, 5, 1)
.eaten(ctx => {
ctx.global.food(ctx)
})
})
})
global.food = ctx => {
const {player} = ctx;
if (!player.level().isClientSide()) return
player.tell(Text.gold('Are you insane!?'))
}
I changed it from global.food to ctx.global.food


Paste version of crash-2024-04-18_20.39.42-server.txt from @fickle agate
knew it
.eaten(ctx => global.food(ctx))```try that
wait without the ctx.global
ctx.global will never work

change .eaten to that
there i edited the main script i sent
you restarted your game and changed your script to this edited version?
Paste version of latest.log, debug.log, startup.log from @fickle agate
ok so apparently it works in a dev environment but not a production? 
either that or it works on build 6.4 120 and below 
Wha
global.food = ctx => {
const { player } = ctx;
if (player.level.isClientSide()) return
player.tell(Text.gold('Are you insane!?'))
}```
just get rid of the parenthases after player.level
instead of player.level()
that one was my fault

Ok I am confused still
@sharp micaSo how does the duration thing work?
What number would be one minute!?
yup
Dat might be why the hunger thing didn't work originally
I did 1 tick. Not 1 second of ticks.

Ok...nvm.
StartupEvents.registry('item', event => {
event.create('uncooked_dorito')
.displayName('§c§l§o§nUncooked Dorito')
.tooltip('§bNot very tasty, perhaps bake it?')
.food(food => {
food
.effect('minecraft:hunger', 20, 255, 1)
.eaten(ctx => global.food(ctx))
})
})
global.food = ctx => {
const {player} = ctx;
if (!player.level.isClientSide()) return
player.tell(Text.gold('Are you insane!?'))
}
This puts me in a load loop

But 1200, 4, 1 doesn't...
a load loop?
aka stuck on loading construct
it crashes again?
Doesn't crash
try js if (player.level.isClientSide()) return
Just gets stuck dispatching construct when I do 20, 255, 1
instead of !player.level.isClientSide
Oh no that works
I'm talking bout the hunger effect
oh i think 20 is supposed to be the probability right

max is 1
I thought last number was probability?
Hunger 5 for 1 min works.
really it should be 254 i think
because max level is 255
and it starts at 0
0 being level "1"
Ohhhhh omg that might work.
Ok so real talk is there a wait command I can implement before having the code apply another effect?
anything outside of that global event requires a full game restart btw
@sharp mica

you mean you want to "wait" before the effect can be re applied?
yes
