2016-11-29 68 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等)插入演播室。如果它是你想要的文本文件,我建議只創建一個新的腳本實例,然後將文本複製到該腳本中。

相關問題