taskライブラリ

ライブラリ日本語解説あり

ひとことで言うと

待つ・あとで実行する・同時に実行する、といった時間に関わる処理のためのライブラリです。task.wait(1) で1秒待てます。

公式の説明(英語):Allows for functions and threads to be coordinated with the engine's scheduler.

使用例

3秒カウントダウン
Script置く場所:ServerScriptService
local count = 3

while count > 0 do
	print(count)
	count -= 1
	task.wait(1)
end
print("スタート!")

スクリプトは、Luauの型チェック(luau-lsp)で確認しています。

関数(7)

名前と書き方説明
spawn
task.spawn(functionOrThread: function | thread, ...: Variant): thread
関数をすぐに、別の流れ(スレッド)で実行します。Calls/resumes a function/coroutine immediately through the engine's scheduler.
defer
task.defer(functionOrThread: function | thread, ...: Variant): thread
今の処理が終わったあとに関数を実行します。Calls/resumes a function/coroutine at the end of the current resumption cycle.
delay
task.delay(duration: number, functionOrThread: function | thread, ...: Variant): thread
指定した秒数のあとに関数を実行します。Schedules a function/coroutine to be called/resumed on the next Heartbeat after the given duration (in seconds) has passed, without throttling.
desynchronize
task.desynchronize(): ()
Causes the following code to be run in parallel.
synchronize
task.synchronize(): ()
Causes the following code to be run in serial.
wait
task.wait(duration: number): number
指定した秒数だけ待ちます。Yields the current thread without throttling.
cancel
task.cancel(thread: thread): ()
spawnやdelayで予定した処理を取り消します。Cancels a thread, preventing it from being resumed.

taskを使う記事

英語の説明とメンバーの一覧は、Roblox Creator Documentation(task)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。

執筆:鈴木孝昌官公庁のWeb・システム開発を担当する現役プロジェクトマネージャー。沖縄マイクラ部 クロスウェーブで、ロブロックス(Roblox)・マインクラフト(マイクラ)・Scratchなどのプログラミングを指導。マイクラカップ沖縄代表チームを指導(第6回・第7回、第7回TBS賞)。
沖縄マイクラ部で、子どもたちにロブロックス(Roblox)やマインクラフト(マイクラ)のプログラミングを教えています。プロフィールと編集方針
Instagramで教室の様子を見る
noteで記事を読む