Issue with functions in Skript

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Sunny_Noob132

Member
Dec 11, 2024
1
0
1
17
I have a bit of an issue with Skript functions, they seem to be non-blocking by default.

For example, if I have the function below:

Code:
function countdown(length: number):
    loop {_length} times:
        broadcast loop-number
        wait 1 second

And I use this function in another section of code:

Code:
every 30 minutes:
    broadcast "refreshing map in 1 minute!"
    countdown(60)
    # code that refreshes the map

I would expect it to broadcast the message, count down, and then refresh the map.

However, it doesn't wait for the countdown to finish and it immediately refreshes the map and continues counting down.

How do I make the cooldown() function synchronous and make it wait for the countdown to finish before refreshing the map?

Server version: 1.21.1 Paper
Skript version: 2.9.5

Addons:
skript-placeholders 1.7.0
skript-gui 1.3
Skuishy 2.8
SkQuery 4.1.10
SkBee 3.6.1
skript-citizens 1.0.0
 
Last edited:
I have a bit of an issue with Skript functions, they seem to be non-blocking by default.

For example, if I have the function below:

Code:
function countdown(length: number):
    loop {_length} times:
        broadcast loop-number
        wait 1 second

And I use this function in another section of code:

Code:
every 30 minutes:
    broadcast "refreshing map in 1 minute!"
    countdown(60)
    # code that refreshes the map

I would expect it to broadcast the message, count down, and then refresh the map.

However, it doesn't wait for the countdown to finish and it immediately refreshes the map and continues counting down.

How do I make the cooldown() function synchronous and make it wait for the countdown to finish before refreshing the map?

Server version: 1.21.1 Paper
Skript version: 2.9.5

Addons:
skript-placeholders 1.7.0
skript-gui 1.3
Skuishy 2.8
SkQuery 4.1.10
SkBee 3.6.1
skript-citizens 1.0.0
Try putting the broadcast part of your code in the function itself (Outside the loop, the line directly after)