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

Broken and replaced

Started by Sebra, 01 March 2016 - 03:54 PM
Sebra #1
Posted 01 March 2016 - 04:54 PM
Is any sure way for Turtle to know it was broken and placed back?
Is any sure way for Turtle to know it was broken, shot down, restarted or chunk reloaded?
What can be added for Turtles to be able to get this info?
Lupus590 #2
Posted 01 March 2016 - 05:42 PM
Have the turtle constantly save the current time to a file, if the file and the result of os.time() differ then the turtle must have been off for some time. You could then assume that you have been moved or in an unloaded chunk.

You could also overwrite os.shutdown to write to a file that the function was used (I believe that breaking and chunk unloading uses a different method). When the turtle starts up it can check that the shutdown file is as expected.

The turtle could also track nearby blocks, if the blocks around it have changed then it has possibly been moved. (Or someone could have just replaced their floor while the turtle was off.)

You will likely have to use a combination of the above.

Also, there is always GPS, if that says different than last time then the turtle has moved. (Unless you change your GPS setup part way through).
Sebra #3
Posted 01 March 2016 - 06:11 PM
Of course we can detect Turtle load process. We can detect time passed from last check saved. It can give us restart event.
But so many ways to get Turtle "off and guess where we are"…
After map load "good morning, where are we?"
After moving to unloaded chunk "who knock me out and where am I now?"
After proper shutdown procedure "Oh, I was turned off gently ;)/> but am I on the same place or in the other dimension completely?"

I want Turtle to know it's "job was interrupted by map/chunk reloaded and should be continued" or "you was picked up and now I need you here".
May be turtle.placementTime() could be added or turtle.getShutdownReason(). Nothing too complex, just way to get little info.
Lupus590 #4
Posted 01 March 2016 - 09:39 PM
If a turtle was picked up and moved then it would likely have been turned on by the player who placed it, have it listen for player input within a timer. if there is no input from before the end of the timer then assume that it was a chunk unload which caused the shutdown.

There is no pre-provided way to detect turtles being broken, so you will have to resort to these convoluted methods.

You could post it as a suggestion: http://www.computercraft.info/forums2/index.php?/forum/20-suggestions/
Sebra #5
Posted 02 March 2016 - 06:52 PM
Thanks. Unanswered question on boot can help.
I try not to make several suggestions at once.
HPWebcamAble #6
Posted 03 March 2016 - 03:57 AM
I try not to make several suggestions at once.

It's fine to. But I doubt dan would implement it.

In the past, for suggestions regarding a 'shutdown' event or something similar, he maintains that it breaks the fourth wall a bit.
Which is true, but I don't think its a good reason not to implement it. Whats wrong with breaking the forth wall in Minecraft once in a while ;)/> ?
Bomb Bloke #7
Posted 03 March 2016 - 04:23 AM
What's wrong with coding a decent reset mechanism?

I mean, real computers don't know when the power's about to be cut (or why), and short of GPS and similar (which CC already offers!), they don't know if they've changed location when they next boot up.

And so code's been written to deal with that. The same can and has been done for CC systems.
HPWebcamAble #8
Posted 03 March 2016 - 11:41 PM
I mean, real computers don't know when the power's about to be cut (or why)

But IRL computers don't cease to exist temporarily when you walk away from them :P/>
95% of the time or more, a real computer is shut down by the user, properly.

In Minecraft however, I'd guess that a computer will almost never be shutdown using os.shutdown, but instead by their chunk unloading

Just out of curiosity, anyone know how OpenComputer handles it?

What's wrong with coding a decent reset mechanism?

Many programs can be coded to assume they will be stopped at any moment. However, every so often I think of a program I'd like to make that can't get around this fact.


Like I said, I doubt dan will implement any type of work around, such as an event being fired. But if he did, I don't think anyone would complain.
Bomb Bloke #9
Posted 04 March 2016 - 01:30 AM
95% of the time or more, a real computer is shut down by the user, properly.

I wish I could say that of my computers… still, that has more to do with me never turning them off than it does their stability levels.

Just out of curiosity, anyone know how OpenComputer handles it?

I assume there's also no system for tracking how/why the systems were shut down there, either. Since the Lua libraries used can save coroutine states or whatever, there doesn't seem to be any point to having one.