如何将自定义数据文件添加到 Roblox DataModel?

How to add custom data files to Roblox DataModel?

我似乎无法将文本数据(例如 CSV、JSON 或 XML 文件)添加到 Roblox DataModelWorkspaceServerStorage 或任何地方真的吗?

关于如何高效执行此操作的任何提示? 理想情况下,Roblox 应该只将文件的内容作为 table 给我。但是,如果有一种方法可以从我必须手动解析的文件中获取原始字符串,我也可以应付。

如果我没记错的话,Roblox 只允许将他们的 文件(RBXM、RBLX 等)插入工作室。如果它是您想要的文本文件,我建议您只创建一个新的脚本实例,然后将文本复制到该脚本。

you cannot add "files" to the DataModel. However you can use the HttpService to load the data from a webserver (also decode and encodeJSON)。 如果你不想那样加载它,你可以使用 Script or ModuleScript 来存储数据。

为了简单起见,您可以像这样使用 multiline strings(请务必阅读 "Nesting quotes"):

local data = [[Here is your
data that can
span over multiple lines,
so just copy-paste the content]]

print("My data: " .. data)

使用 ModuleScript:

return [[Here is your
data that can
span over multiple lines,
so just copy-paste the content]]

ModuleScript 的用法:

local data = require(game.ServerStorage.your.module.script.text.file)
print("My data: " .. data)

如果您希望将 JSON 文本解码为 table:

local data = game:GetService("HttpService"):JSONDecode(require(game.ServerStorage.your.module.script.text.file))

或者在 ModuleScript 中:

return game:GetService("HttpService"):JSONDecode([[Here is your
data that can
span over multiple lines,
so just copy-paste the content]])

您还可以将文本存储在 StringValue