Godleydemon

Farming Script start

Jun 11th, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. --[[Local Variables]]--
  2. local termWidth, termHeight = term.getSize()
  3. local selectItem = 1
  4. local turtleId
  5. local isWirelessTurtle
  6. local messageOutputFileName
  7.  
  8.  
  9. --[Wireless Print Functions]--
  10. isWirelessTurtle = peripheral.isPresent("right")
  11. if (isWirelessTurtle == true) then
  12.   turtleId = os.getComputerLabel()
  13.   rednet.open("right")
  14. end
  15.  
  16. function writeMessage(message)
  17.     print(message)
  18.  
  19.     -- If this turtle has a modem, then write the message to red net
  20.     if (isWirelessTurtle == true) then
  21.       if (turtleId == nil) then
  22.         rednet.broadcast(message)
  23.       else
  24.         -- Broadcast the message (prefixed with the turtle's id)
  25.         rednet.broadcast("[".. turtleId.."] "..message)
  26.       end
  27.     end
  28.  
  29.     if (messageOutputFileName ~= nil) then
  30.       -- Open file, write message and close file (flush doesn't seem to work!)
  31.       local outputFile = io.open(messageOutputFileName, "a")
  32.       outputFile:write(message)
  33.       outputFile:write("\n")
  34.       outputFile:close()
  35.     end
  36. end
  37.  
  38. --[[menu methods]]--
  39. function farmsize()
  40.     term.clear()
  41.     term.setCursorPos(1,1)
  42.     term.write("please input a width of farm and length")
  43.    
  44. end
  45.  
  46. function farmtype()
  47.     term.clear()
  48.     term.setCursorPos(1,1)
  49.     term.write("please select a farm type")
  50.  
  51. end
  52.  
  53. function potatoes()
  54.  
  55. end
  56.  
  57. function wheat()
  58.  
  59. end
  60.  
  61. function carrots()
  62.  
  63. end
  64.  
  65. function sugarcane()
  66.  
  67. end
  68.  
  69. function help()
  70.     term.clear()
  71.     term.setCursorPos(1,1)
  72.     term.write("=========================================")
  73.     term.write("==This program is made by: The Stuntman==")
  74.     term.write("==Set turtle one block behind first row==")
  75.     term.write("==on the left most corner of your farm ==")
  76.     term.write("==make sure there is a chest behind it ==")
  77.     term.write("==then run the program and use menu    ==")
  78.     term.write("=========================================")
  79.     sleep(10)
  80.     menu()
  81. end
  82.  
  83. function Exit()
  84.     running = false
  85. end
  86.  
  87.  
  88. --[[Menu Definitions ]]--
  89. term.write("my name is" ..is.getComputerLabel)
  90. term.write("please select from the following")
  91. mainMenu = (
  92.     [1] = { text = "Farm Size" }, handler = farmsize),
  93.     [2] = { text = "Farm Type" }, handler = farmtype),
  94.     [3] = { text = "Help" }, handler = help),
  95.     [4] = { text = "Exit"}, handler )
  96. )
  97.  
  98. --[[print menu]]--
  99.  
  100. function printMenu( menu )
  101.     for i=1, #menu do
  102.         if i == selectedItem then
  103.             print ("> "..menu[i].text)
  104.         else
  105.             print("   "..menu[i].text)
  106.         end
  107.     end
  108. end
  109.  
  110. --[[ Handler Method]]--
  111. function onKeyPressed(key, menu)
  112.     if key == keys.enter then
  113.         onItemSelected(menu)
  114.     elseif key == keys.up then
  115.         if selectedItem > 1 then
  116.             selectedItem = selectedItem - 1
  117.         end
  118.     elseif key == key.down then
  119.         if selectedItem < #menu then
  120.             selectedItem = selectedItem + 1
  121.     end
  122. end
  123.  
  124. function onItemSelected( menu )
  125.     menu[selectedItem].handler()
  126. end
  127.  
  128. --[[ Main method ]]--
  129.  
  130. function main()
  131.     while running do
  132.     term.clear()
  133.     term.setCursorPos(1,1)
  134.     printMenu(mainMenu)
  135.    
  136.     even, key = os.pullEvent("key")
  137.     onKeyPressed(key,mainMenu)
  138.     end
  139.     end
  140.    
  141. menu()
Advertisement
Add Comment
Please, Sign In to add comment