#Script No Worky 2.0, CTX with a vengeance!

134 messages · Page 1 of 1 (latest)

floral stoneBOT
#

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

slim snow
#

@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!?'))
        })
    })
})
sharp mica
#

when you open a ticket you must provide the script along with logs if its erroring

slim snow
#

I did and there are no errors

sharp mica
#

in the original post ahujel

slim snow
humble canyonBOT
#

Paste version of startup.log from @fickle agate

slim snow
sharp mica
#

its ok

slim snow
humble canyonBOT
#

Paste version of client.log from @fickle agate

slim snow
#

Idk if those help

humble canyonBOT
#

Paste version of latest.log from @fickle agate

slim snow
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 => global.food(ctx))
        })
})
global.food = ctx => {
    const {player} = ctx;
    if (!player.level.isClientSide()) return
    player.tell(Text.gold('Are you insane!?'))
}```
slim snow
sharp mica
#

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

sharp mica
#

of like hunger 3

slim snow
#

BigEyes 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?

#

hmmm Or something

#

@sharp mica Uhhhh

#

It's stuck on dispatching CONSTRUCT

sharp mica
#

that tells me nothing

#

??nologs

slim snow
#

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

sharp mica
slim snow
#

and it worked.

sharp mica
#

stop breaking logic ahujel

slim snow
#

HOW AM I BREAKING LOGIC?

#

It uh...

#

It crashed when I ate da food

humble canyonBOT
#

Paste version of crash-2024-04-18_20.39.42-server.txt from @fickle agate

sharp mica
#

knew it

slim snow
#

How fix

sharp mica
#
.eaten(ctx => global.food(ctx))```try that
#

wait without the ctx.global

#

ctx.global will never work

slim snow
sharp mica
#

there i edited the main script i sent

slim snow
#

Gets stuck in a dispatching construct loop

sharp mica
slim snow
#

Yup

humble canyonBOT
#

Paste version of latest.log, debug.log, startup.log from @fickle agate

sharp mica
#

ok so apparently it works in a dev environment but not a production? whatcat

#

either that or it works on build 6.4 120 and below hmmm

slim snow
#

Idk

#

This is development in it's essence. I'm just laughing at this abusrdity

sharp mica
#

oh its level() thats causing it

#

i forgot kubejs remaps it to just level

slim snow
#

Wha

sharp mica
#
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

slim snow
#

Ok I am confused still

#

@sharp micaSo how does the duration thing work?

#

What number would be one minute!?

sharp mica
#

well, there are 20 ticks a second

#

60x20

slim snow
#

1200

sharp mica
#

yup

slim snow
#

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...

sharp mica
#

a load loop?

slim snow
#

aka stuck on loading construct

sharp mica
#

it crashes again?

slim snow
#

Doesn't crash

sharp mica
#

try js if (player.level.isClientSide()) return

slim snow
#

Just gets stuck dispatching construct when I do 20, 255, 1

sharp mica
#

instead of !player.level.isClientSide

slim snow
#

I'm talking bout the hunger effect

sharp mica
#

oh i think 20 is supposed to be the probability right

slim snow
sharp mica
#

max is 1

slim snow
#

I thought last number was probability?

sharp mica
#

er no

#

yeah youre right

slim snow
#

Hunger 5 for 1 min works.

sharp mica
#

really it should be 254 i think

#

because max level is 255

#

and it starts at 0

#

0 being level "1"

slim snow
#

Ohhhhh omg that might work.

#

Ok so real talk is there a wait command I can implement before having the code apply another effect?

sharp mica
#

anything outside of that global event requires a full game restart btw

sharp mica
#

why do you ping me when im already here?

slim snow
#

I am slow brain

sharp mica
slim snow
#

yes

sharp mica
#

why

#

and not in the constructor no

slim snow
#

uff

#

Holy....

#

1 second of 255 hunger takes like 3 or 4 full hunger bars.

#

It's perfect.

#

It works