Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- exercise10_2
- -- 特定のコンピュータによる命令によって扉を開けるプログラム(メッセージ受信側)
- -- ########### Config ###########
- local open_msg = "Open" -- 開くメッセージ
- local close_msg = "Close" -- 閉めるメッセージ
- local sender_id = 10 -- 命令を送信する側のコンピュータのIDを調べて記述
- rednet.open("right") -- 右側に設置したモデムを使うという宣言
- -- ########### Functions ###########
- function judgeMessage(msg)
- if msg == open_msg then -- もし受信メッセージが"Open"ならば、
- print("Opened the door")
- redstone.setOutput("top", true)
- elseif msg == close_msg then -- もし受信メッセージが"Close"ならば、
- print("Closed the door")
- redstone.setOutput("top", false)
- else -- どれでもなければ、
- print("wrong")
- end
- end
- -- ########### Main ###########
- while true do
- local id, msg = rednet.receive() -- メッセージを待ち受ける
- print(id, msg)
- if id == sender_id then
- print("correct sender!")
- judgeMessage(msg)
- else
- print("incorrect sender!")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement