You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Minecraft基岩版函数中实现类似Python的time.sleep延迟功能?

How to Add a time.sleep()-Style Delay in Minecraft Bedrock Edition Custom Functions

Hey there! If you want to replicate Python's time.sleep() delay in Minecraft Bedrock Edition custom functions—like showing a message, waiting 5 units of time, then showing another—here are two solid methods to make that happen.

Method 1: Use the schedule Command (Simplest Approach)

This is the easiest way to delay a single function call, perfect for your straightforward two-message example.

  • First, create your initial function (let's name it say_first.mcfunction) with the first /say command and schedule the follow-up:
/say this is a test!
# Schedule the second function to run after 5 seconds (100 ticks) — adjust the time as needed
# Use `5t` for 5 ticks (0.25 seconds) if "5 units" refers to game ticks
schedule function say_second 100t
  • Next, create the delayed function (say_second.mcfunction) with your second command:
/say This is executed after the time.sleep
  • To trigger the sequence, run function say_first in-game. The first message will pop up immediately, and the second will appear after your specified delay.

Method 2: Scoreboard Timer (For Complex Delay Logic)

If you need more control—like tracking delays for multiple entities or running checks during the wait—use a scoreboard to count down ticks manually.

  1. First, create a dummy scoreboard to track the timer:
scoreboard objectives add delayTimer dummy
  1. Create the main function (delayed_say.mcfunction) that starts the sequence and sets the timer:
/say this is a test!
# Set the timer to 100 ticks (5 seconds) for the executing entity (@s)
scoreboard players set @s delayTimer 100
# Start a repeating function to check the timer every tick
schedule function check_timer 1t replace
  1. Create the check function (check_timer.mcfunction) that counts down and triggers the delayed action:
# Decrement the timer for all entities with an active delay
scoreboard players remove @a[scores={delayTimer=1..}] delayTimer 1

# When the timer hits 0, run the second message and clean up
execute as @a[scores={delayTimer=0}] run say This is executed after the time.sleep
execute as @a[scores={delayTimer=0}] run scoreboard players set @s delayTimer -1 # Mark as completed
execute as @a[scores={delayTimer=-1}] run schedule clear check_timer # Stop the repeating check

Quick Notes

  • Tick vs. Seconds: Minecraft Bedrock runs at 20 ticks per second. So 5 seconds = 100 ticks, 5 ticks = 0.25 seconds. Adjust the numbers to match your definition of "5 units of time".
  • Function Placement: Save all .mcfunction files in your behavior pack's functions folder (e.g., BP/functions/say_first.mcfunction) and make sure the behavior pack is enabled in your world.

内容的提问来源于stack exchange,提问作者user15270366

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 15:24:10