KubeJS (Old)

KubeJS (Old)

3M Downloads

Wiki tutorial for chat events shows incorrect example for `scheduleInTicks`

BLucky-gh opened this issue · 2 comments

commented

Minecraft Version

1.20.1

KubeJS Version

2001.6.5-build.14

Rhino Version

2001.2.3-build.6

Architectury Version

9.2.14

Forge/Fabric Version

Fabric 0.16.7

Describe your issue

when running

PlayerEvents.chat((event) => {
    // console.log(Object.keys(event.server))

    if (event.message.trim().toLowerCase().includes("creeper")) {
        console.log(event.server.scheduleInTicks)

        event.server.scheduleInTicks(1, event.server, (ctx) => {
            ctx.data.tell(Text.green("Aw man"))
        })
    }
})

I get the following error:

[21:03:28] [Server thread/INFO]: awman.js#5: dev.latvian.mods.kubejs.util.ScheduledEvents$ScheduledEvent kjs$scheduleInTicks(long,dev.latvian.mods.kubejs.util.ScheduledEvents$Callback) [dev.latvian.mods.rhino.NativeJavaMethod]
[21:03:28] [Server thread/ERROR]: awman.js#8: Error in 'PlayerEvents.chat': Can't find method dev.latvian.mods.kubejs.core.MinecraftEnvironmentKJS.kjs$scheduleInTicks(number,net.minecraft.class_1132,function).
[21:03:28] [Server thread/ERROR]: …rhino.EvaluatorException: Can't find method …kubejs.core.MinecraftEnvironmentKJS.kjs$scheduleInTicks(number,net.minecraft.class_1132,function). (server_scripts:awman.js#8)
[21:03:28] [Server thread/ERROR]:   at knot//…rhino.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:67)

The error message says that it can't find the function scheduleInTicks(number, function), and if I console.log the function, it shows sheduleInTicks(long, function), as seen above, which I'm assuming is the issue

Crash report/logs

No response

commented

Yes, your issue is that you can only pass a number and a callback to the function, you cannot pass other arguments such as event.server. How is that a bug?

commented

ah, apologies, I tunnel visioned and didn't see the lack of a event.server in the call signature and forgot when I was summarizing the long call signature in terms of human readable types

in that case this should actually be a wiki issue cause I copied this from the wiki and edited only slightly

I got that from https://kubejs.com/wiki/tutorials/chat

the specific snippet in question is this one (the first on the page)

PlayerEvents.chat(event => {
  // Check if message equals creeper, ignoring case
  if (event.message.trim().toLowerCase() == 'creeper') {
    // Schedule task in 1 tick, because if you reply immediately, it will print before player's message
    event.server.scheduleInTicks(1, event.server, ctx => {
      // Tell everyone "Aw man", colored green. Callback data is the server
      ctx.data.tell(Text.green('Aw man'))
    })
  }
})```

as you can see it passes event.server.

Let me change the issue title accordingly