Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wiki tutorial for chat events shows incorrect example for scheduleInTicks #918

Open
BLucky-gh opened this issue Oct 24, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@BLucky-gh
Copy link

BLucky-gh commented Oct 24, 2024

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

@BLucky-gh BLucky-gh added the bug Something isn't working label Oct 24, 2024
@ChiefArug
Copy link
Contributor

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?

@BLucky-gh
Copy link
Author

BLucky-gh commented Oct 25, 2024

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

@BLucky-gh BLucky-gh changed the title event.server.scheduleInTicks doesn't work Wiki tutorial for chat events shows incorrect example for scheduleInTicks Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants