【问题标题】:Minecraft Computercraft Rednet.broadcast() isn't passing the proper valueMinecraft Computercraft Rednet.broadcast() 没有传递正确的值
【发布时间】:2022-12-20 23:30:47
【问题描述】:

完整的代码本身非常复杂、冗长,而且是新手编写的;我正在尝试通过 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() 以及两者的每一个组合,但我似乎无法让它工作。

【问题讨论】:

    标签: lua computercraft


    【解决方案1】:

    每the documentation for rednet.receive:

    退货 数字发件人ID,任何信息,细绳协议

    您看到的 2 是发件人 ID,而不是消息。而不是xAxis = rednet.receive(),做senderId, xAxis = rednet.receive(),并且类似地为你分配它的值的任何其他地方。 (如果您想知道为什么 print 在消息前显示数字,这就是原因。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 2018-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 2021-08-05
      相关资源
      最近更新 更多