Advertisement
Alexr360

SpeakFriend Mobile

Mar 18th, 2024 (edited)
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached", 0)
  2. modem.open(42) -- Open channel 42 to receive messages
  3.  
  4. modem.transmit(14, 42, "Remote Connected")
  5.  
  6. -- Define the allowed options
  7. local allowedOptions = {"Archives", "Stables", "Lower Bridge", "Upper Bridge", "Entryway", "Turbine Room"}
  8.  
  9. -- Prompt the user to choose from the options
  10. print("Choose one of the following options:")
  11. for i, option in ipairs(allowedOptions) do
  12.   print(i .. ". " .. option)
  13. end
  14.  
  15. -- Validate user input
  16. local userInput
  17. repeat
  18.   print("Enter the number corresponding to your choice:")
  19.   userInput = tonumber(read())
  20. until userInput and allowedOptions[userInput]
  21.  
  22. -- Send the chosen option
  23. local chosenOption = allowedOptions[userInput]
  24. modem.transmit(14, 42, chosenOption)
  25.  
  26. -- Wait for a reply
  27. repeat
  28.   event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  29. until channel == 42
  30. print(tostring(message))
  31. -- Wait for second reply
  32. repeat
  33.   event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  34. until channel == 42
  35. print(tostring(message))
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement