首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Min克拉夫特计算机技术Rednet.broadcast()没有传递适当的值,我太累了,不知道为什么,帮助。请注意

Min克拉夫特计算机技术Rednet.broadcast()没有传递适当的值,我太累了,不知道为什么,帮助。请注意
EN

Stack Overflow用户
提问于 2022-01-12 00:22:07
回答 1查看 214关注 0票数 2

完整的代码本身是非常复杂、冗长和新手编写的,基本上我试图通过rednet将x和z坐标从一台计算机发送到另一个接收方海龟。

接收器

代码语言:javascript
复制
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)

发件人

代码语言:javascript
复制
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()”以及两者的每一个组合,似乎无法使其工作。

EN

回答 1

Stack Overflow用户

发布于 2022-01-12 03:47:25

the documentation for rednet.receive

返回数字senderID、任何消息、字符串协议

你看到的2是发送者的ID,而不是信息。不要使用xAxis = rednet.receive(),而是执行senderId, xAxis = rednet.receive(),类似地,在其他任何地方都要分配它的值。(如果您想知道为什么print会在消息之前显示数字,这就是原因。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70674969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档