Advertisement
Alexr360

Season

Mar 19th, 2024 (edited)
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. function detectSeason()
  2.     -- Check redstone input from the front
  3.     if redstone.getInput("front") then
  4.         return "Winter"
  5.     -- Check redstone input from the back
  6.     elseif redstone.getInput("back") then
  7.         return "Summer"
  8.     -- Check redstone input from the right
  9.     elseif redstone.getInput("right") then
  10.         return "Spring"
  11.     -- Check redstone input from the left
  12.     elseif redstone.getInput("left") then
  13.         return "Fall"
  14.     else
  15.         -- No redstone input detected
  16.         return "no season detected"
  17.     end
  18. end
  19.  
  20. local function bastion()
  21.     local modem = peripheral.find("modem") or error("No modem attached", 0)
  22.     modem.open(15) -- Open 43 so we can receive replies
  23.  
  24.     -- And wait for a reply
  25.     local event, side, channel, replyChannel, message, distance
  26.     repeat
  27.       event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  28.     until channel == 15
  29.  
  30.     -- Process the received message based on its content
  31.     if message == "Season" then
  32.         print(detectSeason())
  33.         modem.transmit(43, 15, detectSeason())
  34.     end
  35. end
  36.  
  37. term.clear()
  38. term.setCursorPos(1, 1)
  39. print("Bastion Network Online!")
  40.  
  41. -- Main loop
  42. while true do
  43.     bastion()
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement