RBXScriptSignalデータ型

データ型日本語解説あり

ひとことで言うと

イベントを表すデータ型です。Connectで関数をつなぐと、イベントが起きたときにその関数が実行されます。

公式の説明(英語):An object that runs connected functions upon a specific occurrence.

使用例

1回だけ反応させる
Script置く場所:パーツの中
local part = script.Parent :: BasePart
local connection

connection = part.Touched:Connect(function(hit: BasePart)
	print(hit.Name .. " がふれた")
	connection:Disconnect()
end)

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

メソッド(4)

名前と書き方説明
Connect
RBXScriptSignal:Connect(func: function): RBXScriptConnection
イベントに関数をつなぎます。戻り値(RBXScriptConnection)でつなぎを切れます。Connects the given function to the event and returns an RBXScriptConnection that represents it.
ConnectParallel
RBXScriptSignal:ConnectParallel(func: function): RBXScriptConnection
Connects the given function to the event and returns an RBXScriptConnection that represents it.
Once
RBXScriptSignal:Once(func: function): RBXScriptConnection
イベントが1回起きたら、自動でつなぎを切ります。Connects the given function to the event (for a single invocation) and returns an RBXScriptConnection that represents it.
Wait
RBXScriptSignal:Wait(): Variant
イベントが起きるまで待ちます。Yields the current thread until the signal fires and returns the arguments provided by the signal.

RBXScriptSignalを使う記事

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

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