2016-11-29 143 views
2

我似乎无法向Roblox DataModelWorkspaceServerStorage或其他任何地方添加文本数据(例如CSV,JSON或XML文件)吗?如何将自定义数据文件添加到Roblox DataModel?

有关如何有效地做到这一点的任何提示? 理想情况下,Roblox应该给我的文件内容为table。但是如果有一种方法可以从手动解析的文件中获取原始字符串,我也可以应付。

回答

2

As already said您无法将“文件”添加到DataModel。但是,您可以使用HttpService从Web服务器加载数据(也可以使用decodeencode JSON)。 如果您不想以这种方式加载,则可以使用ScriptModuleScript来存储数据。

为了方便,你可以使用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

文本
0

如果我没有记错,Roblox只允许将文件(RBXM,RBLX等)插入演播室。如果它是你想要的文本文件,我建议只创建一个新的脚本实例,然后将文本复制到该脚本中。

相关问题