To the point: I've recently been getting into the perilous topic that is persistency in Lua in general, and in ComputerCraft in particular. In my research, I've come across some posts indicating that events should actually "survive" across saving/quitting a world and reloading it (or chunk unloading/reloading). The posts in question are:
- immibis on state saving
- Cloudy commenting on the event queue
Since one of the two is from a ComputerCraft developer, I was quite hopeful. But after some unsuccessful experimentation I decided to have a peek at the Java side of things (I hope this is not considered rude, it was done truly only with the goal of understanding event persistency in mind). From what I saw, the event queue is stored without the expected response IDs for the individual "commands". This results in them having a response ID of -1 after reloading the world, and thus no event will be dispatched on the Lua side.
Therefore my question: is this intended behavior, and if so, for what reason? Storage size/bandwidth? It seems to me that saving the response IDs would not be that bad of an overhead, plus it could even be patched in without breaking backwards compatibility (if it's not present in the save, just fall back to -1). If it is not intended behavior, how do the chances stand of this being fixed anytime soon?
Finally, my workaround: I only needed this in the context of persistently storing a Turtle's position. Somewhat along the lines of what immibis wrote, although a little more simplistic (native call, save id, wait for event; if set when loading wait for event on startup). Seeing as this won't work, here's what I've decided to do instead: check the fuel. This obviously only works if the turtles use fuel (but seriously, why wouldn't they). The basic idea is: save the fuel state before issuing the move command, if there's a reboot while moving wait at the startup for a bit, then check if the fuel level changed. Since only successful moves consume (exactly one) fuel, this is a pretty good indicator as to whether the last movement command was successful or not. It works really well for me, but at the same time is hardly satisfactory, given its hacky nature.
Anyway, I'd be happy to get some official feedback on the not-dispatching-events-for-pending-commands-after-reloads thing. Thanks!
PS: I'm using the latest version at this date, 1.53. Also, though I don't think it's really necessary, here's the (simplified) code I've tested with.
Event driven and broken:
Workaround:
Edit: fixed a derp in the code samples (missing success check around updateState()).
Edit 2: I built a small API based on the mentioned workaround.












