ModuleScriptクラス
ひとことで言うと
他のスクリプトから読み込んで使う「部品」のスクリプトです。何度も使う関数やデータをまとめておき、require()で読み込みます。
公式の説明(英語):A script type that runs once when Global.LuaGlobals.require() is called with it. Returns exactly one value, usually a table of functions, to used by other scripts. Useful for compartmentalizing code.
使用例
local MathUtils = {}
function MathUtils.double(n: number): number
return n * 2
end
return MathUtilslocal ReplicatedStorage = game:GetService("ReplicatedStorage")
local MathUtils = require(ReplicatedStorage:WaitForChild("MathUtils"))
print(MathUtils.double(21))スクリプトは、Luauの型チェック(luau-lsp)で確認しています。
クラスの関係
受け継いでいるクラス:Object → Instance → LuaSourceContainer → ModuleScript
プロパティ(1)
| 名前と書き方 | 説明 |
|---|---|
SourceModuleScript.Source: ProtectedString | The code to be executed. |
受け継いでいるメンバー
Instance から受け継いでいるもの(46)
Archivable・Capabilities・IsInSandbox・Name・Parent・PredictionMode・Sandboxed・AddTag・ClearAllChildren・Clone・Destroy・FindFirstAncestor・FindFirstAncestorOfClass・FindFirstAncestorWhichIsA・FindFirstChild・FindFirstChildOfClass・FindFirstChildWhichIsA・FindFirstDescendant・GetActor・GetAttribute・GetAttributeChangedSignal・GetAttributes・GetChildren・GetDebugId・GetDescendants・GetFullName・GetStyled・GetStyledPropertyChangedSignal・GetTags・HasTag・IsAncestorOf・IsDescendantOf・IsPropertyModified・QueryDescendants・RemoveTag・ResetPropertyToDefault・SetAttribute・WaitForChild・AncestryChanged・AttributeChanged・ChildAdded・ChildRemoved・DescendantAdded・DescendantRemoving・Destroying・StyledPropertiesChanged
Object から受け継いでいるもの(4)
ModuleScriptを使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(ModuleScript)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。