event to tell a computer that it is about to be unloaded
#1
Posted 28 March 2015 - 03:23 AM
#2
Posted 28 March 2015 - 04:55 AM
#3
Posted 28 March 2015 - 02:41 PM
#4
Posted 28 March 2015 - 04:12 PM
#5
Posted 29 March 2015 - 02:01 AM
Lyqyd, on 28 March 2015 - 04:55 AM, said:
This seems quite silly to me. Wouldn't it make sense to add the feature in anyways?
This mod isn't about presenting stuff. It's about programming.
#6
Posted 29 March 2015 - 01:31 PM
I did request this before, but it was not accepted
Edited by Lupus590, 29 March 2015 - 01:35 PM.
#7
Posted 29 March 2015 - 10:43 PM
MKlegoman357, on 28 March 2015 - 04:12 PM, said:
Writing to the HD is the only "good" way, and it a) hammers the HD (at least in a lot of cases), and
There's also the whole "computers don't always start up until they get updated or opened" thing. Speaking of 4th wall breaking...
Edited by The Lone Wolfling, 29 March 2015 - 10:44 PM.
#8
Posted 29 March 2015 - 11:28 PM
The Lone Wolfling, on 29 March 2015 - 10:43 PM, said:
.... which, sadly, is still a thing under 1.73.
The way I see it, warnings when unloads occur would be nice, but I don't see them as viable.
Sure, they'd break the fourth wall, but so does the lack of persistence. The ideal solution would be to implement persistence, but the ramifications of doing that would likely justify calling the result "ComputerCraft 2". So assuming persistence "isn't going to happen", an event would be the "next best thing".
The real issue is that the event just isn't likely to help. Let's say you've got a turtle moving along, and mid-movement, the event goes into its queue. Odds are the server's going to shut down before it gets a chance to catch it - assuming it doesn't just simply discard the event while searching for the "turtle_response" event indicating the movement is complete!
Granted, in the latter case it can be grabbed anyways with decent coroutine management, and to deal with the former it might be possible to have ComputerCraft delay server shutdowns in an attempt to get all its "last second processing" done. But that's still putting aside the point that the event might not ever get a chance to go into the queue in the first place, because MineCraft servers can crash. However you look at it, a script just isn't going to be able to rely on these events, and one which attempts to stands to backfire.
To my understanding, a turtle's fuel level can be relied upon no matter what happens. I gather code has already been written to take advantage of this.
#9
Posted 30 March 2015 - 12:00 AM
Bomb Bloke, on 29 March 2015 - 11:28 PM, said:
Lama did/does this, the post is a bit old now, but I hope to be able to update it for my Hive project
Edited by Lupus590, 30 March 2015 - 12:39 PM.
#10
Posted 30 March 2015 - 12:07 PM
Bomb Bloke, on 29 March 2015 - 11:28 PM, said:
To my understanding, a turtle's fuel level can be relied upon no matter what happens. I gather code has already been written to take advantage of this.
Now, there is actually a solution, and I've got it working, on my machine at least. Unfortunately, it requires a peripheral currently, although I believe it could be implemented without too much trouble into CC itself. The way it works is as follows: the peripheral exposes three methods: writeData, readData, and hasStateChanged. Write saving a string, read reading a string, hasStateChanged returning a boolean. When you call write, it saves the value to NBT. readData returns that data. When you call writeData, it also writes the turtle's current state to NBT. When the turtle is updated for the first time thereafter, or when you call hasStateChanged, it returns if the turtle's state has changed since when you called writeData.
So basically, you can get 90% reliable resyncs by doing the following: writing the current state in the program with writeData(str), then doing whatever. Repeat. On startup, call readData() to get the state, then call hasStateChanged() to see if the last action you were about to do went through.
There still is a race condition, theoretically, but I have yet to encounter it. (If the turtle's NBT is in the middle of being saved when the server goes down. However, there's really no way around this. And on atomic filesystems it shouldn't be a problem anyways.)
(You need readData / writeData because the turtle's filesystem is not atomic with the chunk state.)
#11
Posted 30 March 2015 - 03:37 PM
#12
Posted 30 March 2015 - 05:43 PM
Lyqyd, on 30 March 2015 - 03:37 PM, said:
Let's say you write the current rotation to a file, then rotate, then write the current rotation again. Even ignoring the second issue above, what can happen is that you write the rotation state to the file, then the chunk unloads. So you've written that you are about to take a rotation. But you have no idea if the rotation actually happened or not. Before you say "that won't happen often" - yeah, it does. Often enough that I gave up even trying with my quarry script. And just went to the peripheral-based system above.
Or let's say you are trying to put something in a chest. You check for space, it says there's space, then something else puts something into the chest. All of a sudden when you actually try to put things into the chest it doesn't work. Again: race condition. You cannot, in general, assume that just because you've checked something in advance that it will actually work when you actually go to do it.
Your second example is equivalent to saying that you don't need turtle.move() to return if it moved, because you can always check beforehand with turtle.detect(). And has the exact same flaw.
And with the second issue above these are even worse.
Now, if you've got a method that will reliably rotate, I'm all ears. But until/unless I see someone post a script that, say, rotates left 400 times and comes back to the starting position reliably through restarts / chunk unloads, without relying on external hacks (such as placing blocks or gps+movement or reserving 2 inventory spaces for keeping track of rotation. And the last is still susceptible to a race condition, and the first doesn't work in all cases. Ditto with the second.)...
Edited by The Lone Wolfling, 30 March 2015 - 05:49 PM.
#13
Posted 30 March 2015 - 06:28 PM
#14
Posted 30 March 2015 - 07:05 PM
MKlegoman357, on 30 March 2015 - 06:28 PM, said:
MKlegoman357, on 30 March 2015 - 06:28 PM, said:
MKlegoman357, on 30 March 2015 - 06:28 PM, said:
MKlegoman357, on 30 March 2015 - 06:28 PM, said:
#15
Posted 30 March 2015 - 07:40 PM
The Lone Wolfling, on 30 March 2015 - 07:05 PM, said:
MKlegoman357, on 30 March 2015 - 06:28 PM, said:
Crashes or even closing the window instead of quit to menu seems to force an unload. If the turtle is mid-movement then NBT often isn't saved so you can end up getting one/two empty turtles where the original turtle was moving from. I just can't see this being implemented unless we get the entire persistence thing (and that will happen at the same time we upgrade to Lua 5.3
#18
Posted 31 March 2015 - 12:59 AM
One of the many times where you can realise that text is a very bad way at conversing.
#19
Posted 31 March 2015 - 05:29 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











