完整的代码本身是非常复杂、冗长和新手编写的,基本上我试图通过rednet将x和z坐标从一台计算机发送到另一个接收方海龟。
接收器
rednet.broadcast("Awaiting Input!")
xAxis = rednet.receive() --Have tried tonumber(rednet.receive()) on both same result
zAxis = rednet.receive()
rednet.broadcast(xAxis) --Both values return 2 regardless of what I enter in the sender.
rednet.broadcast(zAxis)发件人
if(irrelevant == "genericstringhere") then
print(rednet.recieve()) --Awaiting Input!
io.write("X Axis: ") --Pizzaz
message = io.read() --Have tried using terms like X and xAxis.
rednet.broadcast(message) --Broadcast whatever tf I typed in.
sleep(0.3)
io.write("Z Axis: ") --More Pizzaz
message = io.read() --Have tried using terms like Z or zAxis
rednet.broadcast(message) --Broadcast whatever tf I typed in. again.
print(rednet.receive()) --Receive xAxis value from sender.
print(rednet.receive()) --Receive zAxis value from sender.
end这两个结果在执行结束时都会返回2,而不是我在io.read()中输入的值,而是尝试了"tonumber()“、"tostring()”以及两者的每一个组合,似乎无法使其工作。
发布于 2022-01-12 03:47:25
每the documentation for rednet.receive
返回数字senderID、任何消息、字符串协议
你看到的2是发送者的ID,而不是信息。不要使用xAxis = rednet.receive(),而是执行senderId, xAxis = rednet.receive(),类似地,在其他任何地方都要分配它的值。(如果您想知道为什么print会在消息之前显示数字,这就是原因。)
https://stackoverflow.com/questions/70674969
复制相似问题