SkriptLang / Skript

Skript is a Spigot plugin which allows server admins to customize their server easily, but without the hassle of programming a plugin or asking/paying someone to program a plugin for them.
https://docs.skriptlang.org
GNU General Public License v3.0
1.07k stars 369 forks source link

Functions which include waiting for a timespan cannot return a value #7100

Open Budgo opened 1 month ago

Budgo commented 1 month ago

Skript/Server Version

https://imgur.com/a/4BPA9Ez

Bug Description

Let's say we have a function x defined as follows:

function x(num1: integer) :: blocks:
    wait a tick
    return all blocks within {location1} and {location2} + {num1}

Upon reloading the Skript containg the function, the error "The return effect can only be use in functions, custom expressions, sections, custom syntax parse sections, and custom conditions"

Expected Behavior

I expect the Skript to reload with no errors.

Steps to Reproduce

Create a new Skript file. Paste the following:

function x(num1: integer) :: blocks:
    wait a tick
    return all blocks within {location1} and {location2} + {num1}

Save, then reload the Skript.

Errors or Screenshots

No response

Other

No response

Agreement

Efnilite commented 1 month ago

I'm pretty sure this is intended. Below is my warning when trying your code. I don't think functions allow waits.

> sk reload test
[15:12:55 INFO]: [Skript] Reloading test.sk...
[15:12:55 INFO]: Line 3: (test.sk)
[15:12:55 INFO]:     A return statement after a delay is useless, as the calling trigger will resume when the delay starts (and won't get any returned value)
[15:12:55 INFO]:     Line: return all blocks within {location1} and {location2} + {num1}
[15:12:55 INFO]:  
[15:12:55 INFO]: [Skript] Encountered 1 error while reloading test.sk! (25ms)
Romitou commented 1 month ago

Probably related to https://github.com/SkriptLang/Skript/issues/4005

TheLimeGlass commented 1 month ago

This has been a known issue for a long time but I don't think there is a issue for it.

Essentially sometimes the error works and sometimes it doesn't. There is a condition that makes the error happen and other times it doesn't. Probably when it's not on the main thread or not on the same event scope.

It should always error.

sovdeeth commented 1 month ago

The error difference is due to skript-reflect registering a different return effect and a different error.

TheLimeGlass commented 1 month ago

The error difference is due to skript-reflect registering a different return effect and a different error.

Oh I remember now.

So skript-reflect should error if it's not in a custom syntax element, and do so silently, because if it uses Skript.error in the init, Skript won't continue onwards with checking other elements.

Which is what is happening here.