Advertisement
Mojokojo69

command

Sep 9th, 2023 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. -- Initialize variables
  2. local channel = 11 -- Channel to send on
  3. local launchTarget = ""
  4. local destination = ""
  5. local modem = peripheral.find("modem")
  6.  
  7. -- Planet and destination options
  8. local planets = { "Mars", "The Moon" }
  9. local destinations = { "Orbit", "Surface" }
  10.  
  11. -- Welcome message
  12. print("Welcome to RareCorp. Space Command.")
  13.  
  14. -- Function to display options and get selection
  15. local function getSelection(options)
  16. local selection = ""
  17. while true do
  18. for i, option in ipairs(options) do
  19. print(i .. ". " .. option)
  20. end
  21.  
  22. local choice = tonumber(read())
  23. if choice and choice > 0 and choice <= #options then
  24. selection = options[choice]
  25. break
  26. else
  27. print("Invalid choice. Please try again.")
  28. end
  29. end
  30. return selection
  31. end
  32.  
  33. -- Get launch target
  34. print("Where would you like to set your launch target to?")
  35. launchTarget = getSelection(planets)
  36.  
  37. -- Get destination type
  38. print("Are you going to Orbit or Surface?")
  39. destination = getSelection(destinations)
  40.  
  41. -- Save choices for later use (You can implement saving the data to a file or other storage if needed)
  42.  
  43. -- Wait for launch command
  44. while true do
  45. print("Type 'launch' when ready.")
  46. local command = read()
  47.  
  48. if command == "launch" then
  49. print("Launching to " .. launchTarget .. " (" .. destination .. ").")
  50.  
  51. -- Send 'start' command
  52. redstone.setOutput("back", true)
  53. sleep(1)
  54. redstone.setOutput("back", false)
  55. modem.transmit(channel, channel + 1, "start")
  56. sleep(14)
  57.  
  58. -- Send 'stop' command
  59. modem.transmit(channel, channel + 1, "stop")
  60.  
  61. print("Launch sequence completed.")
  62. redstone.setOutput("back", true)
  63. sleep(1)
  64. redstone.setOutput("back", false)
  65. break
  66. end
  67. end
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement