Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Lua Script for CC:Tweaked Turtle
- automata = peripheral.find("endAutomata")
- -- Function to perform the main program actions
- local function doProgram()
- print("Redstone signal detected. Starting program...")
- -- 1. Suck up an item
- local sucked, reason = turtle.suckUp()
- if sucked then
- print("Successfully sucked up an item.")
- else
- print("Failed to suck up an item: " .. (reason or "Unknown or no item"))
- -- Decide if you want to continue if suckUp fails.
- -- For now, we'll continue as per the request.
- end
- -- 2. Use automata.useOnBlock() 64 times
- print("Using automata.useOnBlock() 64 times...")
- local successCount = 0
- local failureCount = 0
- for i = 1, 64 do
- -- Check if the automata peripheral and function exist
- if automata and automata.useOnBlock then
- local success, msg = automata.useOnBlock()
- if success then
- successCount = successCount + 1
- -- You might want a small delay here if actions are too rapid
- -- os.sleep(0.1)
- else
- failureCount = failureCount + 1
- print("automata.useOnBlock() failed on attempt " .. i .. ": " .. (msg or "Unknown error"))
- -- Optionally, break the loop or handle the error differently
- end
- else
- print("Error: 'automata' peripheral or 'useOnBlock' function not found.")
- print("Cannot perform automata actions. Skipping remaining uses.")
- break -- Exit the loop if automata is not available
- end
- -- Status update every few iterations
- if i % 10 == 0 then
- print("Automata use progress: " .. i .. "/64")
- end
- end
- print("Finished automata.useOnBlock() attempts. Successes: " .. successCount .. ", Failures: " .. failureCount)
- print("Program cycle complete.")
- end
- -- Main loop
- print("Turtle program started. Waiting for redstone signal from below...")
- while true do
- local redstoneSignal = rs.getInput("bottom")
- if redstoneSignal == true then
- doProgram()
- print("------------------------------------") -- Separator for clarity
- print("Waiting for next redstone signal from below...")
- else
- -- No signal, wait for a second and try again
- -- print("No redstone signal. Waiting...") -- Optional: uncomment for more verbose waiting
- os.sleep(1)
- end
- end
Add Comment
Please, Sign In to add comment