Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables Lua-为什么可以';我是否将.txt文件存储为表?_Variables_Lua_Lua Table_Httpservice_Roblox - Fatal编程技术网

Variables Lua-为什么可以';我是否将.txt文件存储为表?

Variables Lua-为什么可以';我是否将.txt文件存储为表?,variables,lua,lua-table,httpservice,roblox,Variables,Lua,Lua Table,Httpservice,Roblox,我有一个基于python的web服务器,运行在我的raspberry pi上,它可以在Roblox上获取交易汇率。如果你不知道我刚才说了什么,你只需要知道我正在收集某个网页上发生变化的数字。我想将收集到的信息导入我的Roblox游戏中,这样我就可以绘制它(我已经制作了绘图器) 以下是我导入它时所做的操作: bux = game.HttpService:GetAsync("http://tcserver.raspctl.com:5000/AvailableRobux.txt") bux = {bu

我有一个基于python的web服务器,运行在我的raspberry pi上,它可以在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"))

我需要将机器人和票价存储在一个表中。转到其中一个包含速率数据的URL,您将看到它已经为Rbx.Lua表格式化,它只需要大括号。如何将数据转换为表格?

您不能像这样将字符串转换为表格,您需要通过沿分隔符(逗号)将组件拆分为表格。我建议去掉空格,只在数据条目之间加逗号

这是一个你需要的例子。explode函数来自我发布的链接。我还没有测试过

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)

谢谢你的回复。提供的脚本工作正常,拆分字符串页面也有帮助。不过我不需要删除空格。