Lua/Computercraft监听但也能正常工作?
我正在尝试使用computercraft在Tekkit上制作一个计算机系统/网络 Computecraft是一种基于Lua的修改,在Minecraft/Tekkit和其他修改包中运行 基本上,我目前正在使用无线路由器执行以下操作:Lua/Computercraft监听但也能正常工作?,lua,listener,minecraft,computercraft,Lua,Listener,Minecraft,Computercraft,我正在尝试使用computercraft在Tekkit上制作一个计算机系统/网络 Computecraft是一种基于Lua的修改,在Minecraft/Tekkit和其他修改包中运行 基本上,我目前正在使用无线路由器执行以下操作: rednet.open('top') -- Open Connection to the wireless router print ("test") input = read() rednet.receive() -- Listen for messages se
rednet.open('top') -- Open Connection to the wireless router
print ("test")
input = read()
rednet.receive() -- Listen for messages send/broadcasted
if message then
print (message)
end
我正在尝试对我的所有系统进行如下更改:
rednet.open ('top')
-- Do all normal stuff
rednet.receive()
if message == "Lock202" then
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
print ("Alert In Progress, Terminal Locked")
end
通过做所有正常的事情,我希望用户能够导航和使用计算机的功能。但是当调用rednet.receive()
时,它会冻结并等待传入消息
我希望它在后台运行,并且只在收到消息时才运行
我试着查看文档、帮助网站。考虑到Lua编码器的可用范围,我们将这个问题带到这里。命令rednet.receive()的参数中可以有一个参数,即“超时”
这是以秒为单位的。它也是一个浮点数(十进制数),例如4.50、1.23。等等
这意味着它将在这段时间内收到
实现你想要的一个好方法是让另一台计算机不断地接收信息,然后向你想要的计算机发出红石信号,进行模块化的接收,并按照
function Check()
If rs.getInput("back") then
local id, message = rednet.receive(5)
print("Receiving Message")
end
end
另一台计算机将执行以下操作:
computerid = 50
id, message = rednet.receive()
rs.setOutput("back",true)
sleep(1)
rednet.send(computerid, message)
rs.setOutput("back",false)
computerid将等于您要运行的原始计算机的ID。在运行代码时,您还必须定期使用Check()函数,除非收到消息,否则它不会影响计算机。在这种情况下,它会在“rednet.receive”参数中指定的时间内收到消息
希望这有帮助
--EwilDawe命令rednet.receive()的参数中可以有一个参数,即“超时”
这是以秒为单位的。它也是一个浮点数(十进制数),例如4.50、1.23。等等
这意味着它将在这段时间内收到
实现你想要的一个好方法是让另一台计算机不断地接收信息,然后向你想要的计算机发出红石信号,进行模块化的接收,并按照
function Check()
If rs.getInput("back") then
local id, message = rednet.receive(5)
print("Receiving Message")
end
end
另一台计算机将执行以下操作:
computerid = 50
id, message = rednet.receive()
rs.setOutput("back",true)
sleep(1)
rednet.send(computerid, message)
rs.setOutput("back",false)
computerid将等于您要运行的原始计算机的ID。在运行代码时,您还必须定期使用Check()函数,除非收到消息,否则它不会影响计算机。在这种情况下,它会在“rednet.receive”参数中指定的时间内收到消息
希望这有帮助
--艾维达威
这是一个功能,将基本上多线程您的程序。。。所以你可以
function listen()
while true do
id, msg, distance = rednet.receive()
FUNCTION_THAT_RUNS_STUFF(id, msg, distance)
sleep(1)
end
end
function main_loop()
while true do
--do your other stuff in here
end
end
--end of file run everything
parrallel.waitForAll(listen, main_loop)
这是一个功能,将基本上多线程您的程序。。。所以你可以
function listen()
while true do
id, msg, distance = rednet.receive()
FUNCTION_THAT_RUNS_STUFF(id, msg, distance)
sleep(1)
end
end
function main_loop()
while true do
--do your other stuff in here
end
end
--end of file run everything
parrallel.waitForAll(listen, main_loop)
我所做的是我有一台运行os.pullEvent的电脑,还有一大堆其他电脑收集信息并通过rednet发送,这使得只有一台电脑像那样被卡住了,尽管其他电脑几乎无法使用,当然,如果你像我那样做,你可以让它检测钥匙和rednet_消息等等。我所做的是,我有一台电脑运行os.pullEvent,还有一大堆其他电脑收集信息并通过rednet发送,这使得只有一台电脑像那样卡住,尽管其他电脑几乎无法使用,当然,如果你像我那样做,你可以让它检测钥匙和rednet_消息等等。文档建议在后台使用
Parallel.waitForAny
等待rednet.receive
。文档建议在后台使用Parallel.waitForAny
等待rednet.receive
。