Myros27

farmBot V2

May 19th, 2025 (edited)
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. -- Lua Script for CC:Tweaked Turtle
  2. automata = peripheral.find("endAutomata")
  3. -- Function to perform the main program actions
  4. local function doProgram()
  5.     print("Redstone signal detected. Starting program...")
  6.  
  7.     -- 1. Suck up an item
  8.     local sucked, reason = turtle.suckUp()
  9.     if sucked then
  10.         print("Successfully sucked up an item.")
  11.     else
  12.         print("Failed to suck up an item: " .. (reason or "Unknown or no item"))
  13.         -- Decide if you want to continue if suckUp fails.
  14.         -- For now, we'll continue as per the request.
  15.     end
  16.  
  17.     -- 2. Use automata.useOnBlock() 64 times
  18.     print("Using automata.useOnBlock() 64 times...")
  19.     local successCount = 0
  20.     local failureCount = 0
  21.     for i = 1, 64 do
  22.         -- Check if the automata peripheral and function exist
  23.         if automata and automata.useOnBlock then
  24.             local success, msg = automata.useOnBlock()
  25.             if success then
  26.                 successCount = successCount + 1
  27.                 -- You might want a small delay here if actions are too rapid
  28.                 -- os.sleep(0.1)
  29.             else
  30.                 failureCount = failureCount + 1
  31.                 print("automata.useOnBlock() failed on attempt " .. i .. ": " .. (msg or "Unknown error"))
  32.                 -- Optionally, break the loop or handle the error differently
  33.             end
  34.         else
  35.             print("Error: 'automata' peripheral or 'useOnBlock' function not found.")
  36.             print("Cannot perform automata actions. Skipping remaining uses.")
  37.             break -- Exit the loop if automata is not available
  38.         end
  39.         -- Status update every few iterations
  40.         if i % 10 == 0 then
  41.             print("Automata use progress: " .. i .. "/64")
  42.         end
  43.     end
  44.     print("Finished automata.useOnBlock() attempts. Successes: " .. successCount .. ", Failures: " .. failureCount)
  45.     print("Program cycle complete.")
  46. end
  47.  
  48. -- Main loop
  49. print("Turtle program started. Waiting for redstone signal from below...")
  50. while true do
  51.     local redstoneSignal = rs.getInput("bottom")
  52.  
  53.     if redstoneSignal == true then
  54.         doProgram()
  55.         print("------------------------------------") -- Separator for clarity
  56.         print("Waiting for next redstone signal from below...")
  57.     else
  58.         -- No signal, wait for a second and try again
  59.         -- print("No redstone signal. Waiting...") -- Optional: uncomment for more verbose waiting
  60.         os.sleep(1)
  61.     end
  62. end
Add Comment
Please, Sign In to add comment