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

There is no delay with smaller than 1 tick "wait for" times #35

Closed
Pilvinen opened this issue Mar 27, 2016 · 4 comments
Closed

There is no delay with smaller than 1 tick "wait for" times #35

Pilvinen opened this issue Mar 27, 2016 · 4 comments
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something.

Comments

@Pilvinen
Copy link

I just spend 3 hours yesterday trying to figure out why my code doesn't work and it all came down to this:

command /testbug:
  trigger:
    set {_counter} to 1000
    loop 1000 times:
      subtract 1 from {_counter}
      wait for 0.0125 seconds
      broadcast " DEBUG: This delay should take 12,5 seconds %{_counter}%"

The issue:
If the "wait for" time is less than 1 tick there will be no delay of any kind, it's being rounded downwards to 0.

As I understand Minecraft has 20 tick cycle to execute everything in main thread. I don't know how Skript is built - perhaps it's tied up to the main thread and perhaps some things are run in their own thread the frequency of which I can only guess. But either there should be a delay smaller than 1 tick (which at the moment seems unlikely to be possible) or - in my humble opinion - the wait time should at least be rounded up to the smallest span of time that Skript is capable of waiting in the case where there is a wait time defined which is more than 0 to protect stupid users like me who do not fully understand the undocumented inner workings of Skript. I can see some possible use scenarios for a "wait for 0 ticks/seconds" which can be used to release events and keep running the rest of the code while the event has been released (but without delay).

It's hard to say from my point of view whether this is a feature (and why?) or a bug but it should probably be looked into.

If it's a feature you should probably either round upwards and/or give error/warning message when loading the skript: "the shortest amount of time you can wait is 1 ticks"

@TheBentoBox
Copy link
Member

Out of curiosity, could you try doing "wait for 0.04 seconds" and see if it rounds down to 0?

@TheBentoBox
Copy link
Member

You're right about what the issue is. I think it's impossible for Skript (or any plugin) to do anything in smaller increments than 1/20th of a second. Minecraft doesn't process things quicker than that, so you can't make it do anything quicker than that.

@bensku
Copy link
Member

bensku commented Mar 27, 2016

As far as I know, Skript runs even delayed tasks in main thread. Minecraft is not thread safe, excluding the chat, and with Spigot even that is not thread safe.

I will see if I can make it report clear error, though.

@bensku bensku added the investigating The core developers are currently investigating this issue. Usually used for complex cases. label Mar 27, 2016
@TheBentoBox
Copy link
Member

TheBentoBox commented Dec 24, 2016

Currently, we are still able to write something like wait 0.5 ticks, which there probably should be as it's impossible. Recommend that, when given a timespan in ticks, the provided amount is run through a ceil, with a warning (not error) provided. Something like Warning: you can only wait a whole number of ticks. Rounding up to %ceil(ticks)%. Obvious pseudocode there within the %'s but you get the idea.

Tagging as enhancement because this isn't exactly a bug, but a better error would be an improvement (and rounding up will prevent crashes if people have a big loop with wait 0.5 ticks expecting there to be some sort of delay between iterations).

@TheBentoBox TheBentoBox added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label Dec 24, 2016
@bensku bensku removed the investigating The core developers are currently investigating this issue. Usually used for complex cases. label May 24, 2017
@bensku bensku closed this as completed Aug 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something.
Projects
None yet
Development

No branches or pull requests

3 participants