This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
emufossum13's profile picture

turtle help

Started by emufossum13, 10 January 2013 - 12:52 PM
emufossum13 #1
Posted 10 January 2013 - 01:52 PM
Hello, I've only been working with computercraft and turtles for about a month. I've been able to get around ok, but I'm having an issue with a program I'm writing for a turtle. Basically I want the turtle to only run the program when it detects a redstone input. I tried to write a program where I declared a function as everything I want the turtle to do, then have the turtle running on a while true do loop to detect an input, and to only run the function when it detected an input. Unfortunately it crashed my turtle, and I wasn't able to get the program back, so I can't post any of my work. If you guys could help me out, it would be much appreciated. Like I said, I know my way around, but I'm certainly not an expert.
theoriginalbit #2
Posted 10 January 2013 - 01:54 PM
have a look at the parallel api. you can use this to run the redstone listener and the execution code at the same time. then use error() to quit the program.
ChunLing #3
Posted 10 January 2013 - 09:21 PM
Your while loop probably crashed because it failed to yield. Then I guess you broke your (unlabeled) turtle, losing all the data (next time use Ctrl-R or Ctrl-S, Ctrl-T doesn't work on computers shut down for failure to yield).

If you were in SSP then you can still access that data, it will be under the save world folder in the computer\ID subfolder (ID being the id of the turtle before you broke it, which you probably don't know but might be able to guess).

Still, you were mostly on the right track, it sounds like to me.
while true do
os.pullEvent("redstone")
if rs.getInput("back") then callFunction() end
end
Probably the only thing different from what you were doing is the os.pullEvent("redstone"), which makes the turtle yield until it pulls a redstone event.
emufossum13 #4
Posted 11 January 2013 - 08:48 AM
Thank you very much for your reply's to my question. This has to be the fastest response I've ever gotten on a forum. I have classes right now, but I will be sure to try out your suggestions as soon as I can
emufossum13 #5
Posted 11 January 2013 - 09:21 AM
It Works :D/>
Thank you very much ChunLing