我不确定在哪里可以看到我可以用来捕获另一个程序中加载的程序中的变量更改。
这是我的代码,虽然很乱:
function launch()
shell.run("clear")
print("Preparing for first time run.")
sleep(1)
print("")
local program = netTest()
local file = loadstring(program)
file()
sleep(3)
shell.run("clear")
end
function netTest()
local output = http.get("http://pastebin.com/raw.php?i=hzZv3YH2")
if output then
local contents = output.readAll()
output.close()
return contents
else
print("Empty response")
return false
end
end
local program = netTest()
local file = loadstring(program)
launch()
这是它调用的代码:
function ping()
fails = 0
pingResult = 0
print("Testing Internet Connection.")
print("")
oldx, oldy = term.getCursorPos()
print("Connection Test 1")
http.request("http://www.google.com/")
if os.pullEvent() == "http_success" then
local oldx, oldy = term.getCursorPos()
term.setCursorPos(46,oldy-1)
io.write("Passed")
else
local oldx, oldy = term.getCursorPos()
term.setCursorPos(46,oldy-1)
io.write("Failed")
fails = fails+1
end
sleep(1)
print("Connection Test 2")
http.request("http://www.microsoft.com/")
if os.pullEvent() == "http_success" then
local oldx, oldy = term.getCursorPos()
term.setCursorPos(46,oldy-1)
io.write("Passed")
else
local oldx, oldy = term.getCursorPos()
term.setCursorPos(46,oldy-1)
io.write("Failed")
fails = fails+1
end
sleep(1)
print("Connection Test 3")
http.request("http://www.example-failure.com/")
if os.pullEvent() == "http_success" then
local oldx, oldy = term.getCursorPos()
term.setCursorPos(46,oldy-1)
io.write("Passed")
else
local oldx, oldy = term.getCursorPos()
term.setCursorPos(46,oldy-1)
io.write("Failed")
fails = fails+1
end
sleep(1)
if fails == 0 then
print("")
print("")
print("Test Complete, no failures detected.")
sleep(1.5)
elseif fails == 1 then
print("")
print("")
print("1 connection failures detected. A Website Host might be down however connectivity is still there.")
print("")
print("Test Complete.")
sleep(1.5)
elseif fails == 2 then
print("")
print("")
print("2 connection failures detected. Possible limited web connectivity.")
print("")
print("Test Complete.")
sleep(1.5)
elseif fails == 3 then
print("")
print("")
print("Catastrophic connection failure detected. A firewall or improper internet settings may be the problem.")
print("")
print("Test Complete.")
pingResult = __pingResult + 3
sleep(1.5)
end
end
ping()
正如您所看到的,它在外部运行一个程序,该程序将通过向几个页面发出 http 请求来测试连接,以确保连接到 Internet。(我知道,这有点蹩脚,但我还在学习)。
基本上,如果连接在所有 3 个阶段都读取失败,它将使我的 pingResult 变量 = 3。我想要从第一个调用我的 Internet 实用程序的程序中做的是记录该变量的设置。如果在关闭时将其设置为 3,则记录该变量的设置,然后为简单起见,打印该变量,以便我可以看到它是 0 或 3。我稍后会用它做一些事情,但你会明白它的要点.
我已经尝试了其他几件事,但似乎无法弄清楚我是如何做到这一点的。看到我还是新手,我尝试了随机的东西,但似乎没有任何效果,或者我只是做错了,所以我不知道该怎么做。这几天一直在尝试,但没有成功。