【发布时间】:2017-04-13 00:50:14
【问题描述】:
我似乎无法将文本数据(例如 CSV、JSON 或 XML 文件)添加到 Roblox DataModel、Workspace、ServerStorage 或其他任何地方?
关于如何有效地做到这一点的任何提示? 理想情况下,Roblox 应该只将文件内容作为table 给我。但如果有办法从我必须手动解析的文件中获取原始字符串,我也可以应付。
【问题讨论】:
我似乎无法将文本数据(例如 CSV、JSON 或 XML 文件)添加到 Roblox DataModel、Workspace、ServerStorage 或其他任何地方?
关于如何有效地做到这一点的任何提示? 理想情况下,Roblox 应该只将文件内容作为table 给我。但如果有办法从我必须手动解析的文件中获取原始字符串,我也可以应付。
【问题讨论】:
如果我没记错的话,Roblox 只允许将他们的文件(RBXM、RBLX 等)插入工作室。如果它是您想要的文本文件,我建议只创建一个新的脚本实例,然后将文本复制到该脚本。
【讨论】:
As already said 您不能将“文件”添加到 DataModel。但是,您可以使用HttpService 从网络服务器加载数据(也可以使用decode 和encode JSON)。 如果不想这样加载,可以使用Script 或ModuleScript 来存储数据。
为方便起见,您可以像这样使用multiline strings(请务必阅读“嵌套引号”):
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 文本解码为表格:
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
【讨论】: