3

我在我的树莓派上运行了一个基于 python 的网络服务器,它可以在 Roblox 上抓取交易货币汇率。如果你不知道我刚才说了什么,你只需要知道我正在收集在某个网页上发生变化的数字。我想将这些收集到的信息导入我的 Roblox 游戏,以便绘制它(我已经制作了绘图器)。

这是我为导入它所做的:

bux = game.HttpService:GetAsync("http://tcserver.raspctl.com:5000/AvailableRobux.txt")
bux = {bux}
tix = game.HttpService:GetAsync("http://tcserver.raspctl.com:5000/AvailableTickets.txt")
tix = {tix}

这给了我一个 404 响应。如果我从我的计算机(在同一网络上)访问 Web 服务器,它也会给我一个 404 响应。我知道我正确地进行了端口转发,因为以下 lua 行确实有效。

print(game.HttpService:GetAsync("http://tcserver.raspctl.com:5000/AvailableRobux.txt"))

我需要将 robux 和票价存储在表格中。转到带有速率数据的 URL 之一,您会看到它已经针对 Rbx.Lua 表进行了格式化,它只需要花括号。如何将我的数据转换为表格?

4

1 回答 1

4

您不能只将字符串转换为这样的表格,您需要通过沿分隔符(逗号)将组件拆分为表格。有关在 Lua 中拆分字符串的信息,请参阅此页面。我建议去掉空格,在数据条目之间只使用逗号。

这是您需要的示例。爆炸功能来自我发布的链接。我还没有测试过。

function explode(d,p)
  local t, ll
  t={}
  ll=0
  if(#p == 1) then return {p} end
    while true do
      l=string.find(p,d,ll,true) -- find the next d in the string
      if l~=nil then -- if "not not" found then..
        table.insert(t, string.sub(p,ll,l-1)) -- Save it in our array.
        ll=l+1 -- save just after where we found it for searching next time.
      else
        table.insert(t, string.sub(p,ll)) -- Save what's left in our array.
        break -- Break at end, as it should be, according to the lua manual.
      end
    end
  return t
end

bux = game.HttpService:GetAsync("http://tcserver.raspctl.com:5000/AvailableRobux.txt")
bux = explode(",",bux)
tix = game.HttpService:GetAsync("http://tcserver.raspctl.com:5000/AvailableTickets.txt")
tix = explode(",",tix)
于 2015-03-15T22:16:35.127 回答