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

what makes a turtle shutdown doing runtime?

Started by pjensen68321, 12 June 2013 - 05:51 AM
pjensen68321 #1
Posted 12 June 2013 - 07:51 AM
Title: what makes a turtle shutdown doing runtime?

i'm making a multiagent mining system, and every now and then the turtle just shutdown, and i have to run around in lava and creepers to find the turtle to start it.
i got an infinite loop witch ends in a sleep(0.1) (read that it could be a good idea, not sure why) but seems that they still shutdown.
i got a flower collector witch works the same way and also shutdown.
should i make it wait longer, or what can the problem be?

thanks.
Cranium #2
Posted 12 June 2013 - 11:16 AM
Split to new topic.
From what you are describing, it sounds like the chunk that the turtles are in are being unloaded. Are you near the turtles all the time, or do you leave to do something else? Turtles will only run while the chunk is loaded, otherwise they shut down.
Bomb Bloke #3
Posted 12 June 2013 - 11:49 AM
This should go without saying, but there's no way to provide anything other then a guess without actually seeing your code and any error messages it produces.
H4X0RZ #4
Posted 12 June 2013 - 11:54 AM
Addition to Craniums post:
You can use a chunkloader for this. (The chunckloader from immibis-peripherals for example)
pjensen68321 #5
Posted 12 June 2013 - 04:02 PM
hmm its about 500 lines of codes i think, but its easy written. I can give you a pastebin to a downloader for the 2 files i make (on my dropbox so i can update on the fly.)
pastebin get -removed-

this is a pastebin for a file wich downloads a file who downloads more files. don't worry no virus. you can just copy paste urls in a browser.
the two files that is needed are the miningWorkerCode.lua and the odo.lua
the odo.lua is a file wich takes care of the movement, and the miningWorkerCode is yea… the code :)/> but i think it might be in odo.lua the problem is.
and there might be some danish comment and something wich is not used. but look for the mainloop function to see the actual run. every function should be kinda self explanatory.

you can also look at this. it's the same odo file but a smaller worker code, its for a flower collector. same problem, just smaller code. the files of interest here is flower.lua and odo.lua
pastebin get -removed- update

i do have chunkloaders. not sure if it works if i just stand near them. but i usally dosen't go that far.
the turtles dig in a radius of 60 from a server witch is a litle shorter that the radius of rednet. the server runs aswell as the gps computers.
btw the cunkloader is the one that cost 5 gold an enchantment table and one more thing a can't remember.
The chunkloader is set for a radius of 6 in a square.

if you got time to look at it it would help me alot, couse this is very strange. it can run several times and the sudently it stops.
Edited on 16 June 2013 - 07:21 AM
Bomb Bloke #6
Posted 12 June 2013 - 08:12 PM
So miningWorkerCode.lua and odo.lua. I also see a miningWorkerStarter.lua and hutBuild.lua, which I link here in case they come up later.

My bet is on missed rednet messages. I've coded a similar sort of client/server setup, and I've found that sometimes, for reasons unknown, a message will either fail to get sent or fail to be received. The transmitting computer ticks along as usual but the receiving machine just doesn't get the message (even if I force the server to wait at least a second before replying). If using rednet.receive() without a timeout, as you are doing in minerWorkingCode, it'll eventually result in turtles simply halting with no errors in the terminal (which I assume is what you're seeing - you haven't elaborated on that).

My solution was to set a time out for about five seconds and then attempt to message the server again if I hadn't received anything back. In short, you need to account for dropped packets.

Eg, rewrite something like this:

		rednet.send(serverID,"mining_getTourchChest")
		id,message = rednet.receive()
		values = split(message,":")
		for i=1,4 do
			tourchChest[i] = values[i+1]
		end

To this:

		message = nil
		while not message do
			rednet.send(serverID,"mining_getTourchChest")
			id,message = rednet.receive(5)
		end
		values = split(message,":")
		for i=1,4 do
			tourchChest[i] = values[i+1]
		end

I don't think odo is affected by this, as you only use rednet for GPS positioning there. Would have to read a bit more of it. Again, knowing exactly what you mean by your turtles "shutting down" would be helpful. Do they give errors? Reboot? Or simply halt?
pjensen68321 #7
Posted 13 June 2013 - 03:09 AM
ahh okay thanks, i will take this into account next time.
but this isn't the problem. the problem is that it completely shuts down. i can see that it's starting up when i right click it. you know boot screen and all that. its like it get an error and then turns off like if you hold ctrl + s.

can it be because that a CC computer only got a limit of cpu time in a specific real time. i got a system wich chop down redwood trees, and this waits for the tree to grow, my idea was that this can run forever because it has a os.sleep(5) where it waits.
The miner just keeps running forever and never waits for anything, wich means no real os.sleep()

the flower collector has the same problem, it dosn't communicate other that with the gps. but only the two first moves then it has updatet the position and the direction (the odo file). it also runs forever. (removes flowers and grass, fetch some bonemeal, drop bonemeal, remove flower and gras…. and so on…)

the miningWorkerStarter.lua is downloaded and renamed startup wich just says
dofile("/update")
dofile("/mining/workerStart")
so everytime it boots it runs these to lines. wich updates the program and run the miner code.

the hut build is a script wich build the whole setup. dig down to button set the gps computers and the server. places the drop chest and fuel chest. i do not use the torch chest anymore thats why its in a if false then …. end.
if you want to do this file ask me first and i will write a quick guide of how stuff should be places for this script to work… but this dosn't program the computers… yet….
Bomb Bloke #8
Posted 13 June 2013 - 08:29 AM
Ok, so actual reboots. Sorry for doubting; I work tech support and making sure people mean what they're saying is ingrained. ;)/>/>

Off the top of my head, I can think of two possible causes. The first is failure to yield: if a script runs for too long without cease, the computer will often "crash" (and then restart when the player next interacts with it). Sleeping is indeed one way to "cease", but all turtle movement commands (successful or not) should also trigger a yield (as do most commands that "wait" for any reason, eg rednet.receive()). At a glance I can't see any spot where you're running code for extended periods without yielding, however (loops are the obvious place to start looking).

Another possibility is an invalid function call. I've seen one script presented here that exited without error because incorrect parameters were passed to a simple term.setCursorPos() command. That one was a bit of a head-scratcher for a while until I had some debug messages printed in order to trace the break point.

(Well, actually it was trying to set the cursor to just above the top of the screen, so I guess maybe it was technically successful in doing so but printed the error out of bounds!)

In your case screen output of your program's progress isn't helpful, but you might consider cycling the names of your functions through a table as they're called, and periodically writing that table to a file on the turtle's drive. This'd provide you with something of a makeshift stack-trace to review after a crash, as depending on how often you saved the file and how many function calls you stored in it, you'd have some idea what the program was doing when it went down. One save per call would be ideal but would obviously result in heavy drive access.

Sorry I've nothing concrete. Getting a bit late here.
pjensen68321 #9
Posted 13 June 2013 - 08:36 AM
he no problem know the feeling. i'm an robotics engineer so i should know what i do… :)/> "should"…

thanks. i will try that and see it's the same place it get stuck (or what ever we call this)
i have also heard that maybe it could be caused by the chunk-loaders. i have tried to make a chunk-loading turtle instead to see if this helps. if not i will try putting it in another age. but i do not got the right pages yet.
so still got some debugging to do. but thanks for the time. really appreciate it…
pjensen68321 #10
Posted 14 June 2013 - 02:32 PM
yay got i to work. i found an error. in my odo file. I have made my own variable for the fuel wich is checked, and if i got fuel i move if not i stay. it worked just fine, i just forgot to update the variable when i refuelled my turtles. so now i correctet it (properly gonna remove the internal variable) and it has been running all day.
the reasen they shutdown, was that when it "ran" out (the counter, not the actual fuel level) it would stay infinitely and try to move, but since it couldn't i would just stay an make a loop very fast. i implementet a lot os sleeps all around and suddently they didn't shutdown, they just stood still, but in random states. then it hit my. the fuel value. stupid me…

i don't blame you for nat finding the error, it would have taken you forever to find when you don't know the code. but thanks for the help.
and for the advice about losing packets, i will implement a fail safe for that.

a food node. chunk loaders, do work, stupid errors do not :)/>