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

Are resources guaranteed to be available when CC says they are available?

Started by LBPHacker, 05 August 2014 - 04:12 PM
LBPHacker #1
Posted 05 August 2014 - 06:12 PM
Just making sure.

Let's suppose we've got a monitor (substitue monitor with anything here) connected to a computer. The computer gets an event, processes it, and as a result it prints something to the monitor. But oh noes, the monitor's gone, the user had broken it before the computer could finish processing the event.

Question one: Is such a scenario possible? (I mean if the user interactions were processed after or before, but not concurrently with the computer doing its job, this whole mess couldn't happen.)

Question two: If it is possible, what would happen to the computer? Would it continue working like nothing had happened? If so, would it see the monitor detached in the next event? Or would the computer crash?
Lyqyd #2
Posted 05 August 2014 - 06:18 PM
I don't know if, in that specific scenario, the player would be able to time it well enough. If you had a series of actions (monitor calls, for example), and you interrupted that process, you'd most likely get an error in the peripheral API (or your program, if it has error levels set correctly). The error would probably be something along the lines of "no such peripheral". Is there an underlying problem/question leading you to ask this? Seems like you have something other than a monitor in mind.
LBPHacker #3
Posted 05 August 2014 - 06:46 PM
Nope, not much. I'm working on a VFS (yup, with peripherals in it) and this question (totally randomly) came up when I was thinking about how to actually handle those bloody peripherals. Then it occured to me that if stars aligned and a player managed to break something that was being used by a computer, hell would break loose anyway, no matter how the Lua side would handle it.

Slamming a hammer into a printer while it's printing isn't good practice in real life either, after all. If you still want your document printed, that is.
theoriginalbit #4
Posted 06 August 2014 - 12:28 AM
Okay so I came across the answer a while back while testing Iron Note Blocks with MoarPeripherals and my Peripheral-Framwork.
If the peripheral is directly connected to the computer it will error the program.
If the peripheral is connected via a network cable and you turn off the modem before removing, the program will error.
If however you remove the peripheral without turning off the modem it will silently error, your program will still run and think it is interacting with the peripheral, even though it doesn't exist. You can even put a different peripheral in it's place, and if you place down a new modem you'll see it it active, if you deactivate and activate it again it will even still be bound to the old peripheral, and the program still won't error, you'd need to destroy the modem and replace it before using the new peripheral.
LBPHacker #5
Posted 06 August 2014 - 08:24 AM
Yup, that's what I was looking for. I just knew there would be some lameness bad coding around those cables.
Edited on 06 August 2014 - 08:13 AM
theoriginalbit #6
Posted 06 August 2014 - 08:30 AM
'lameness' no, bad coding, yes. Its technically a bug, I'd say that Dan is forgetting to disconnect the modem when he pops it off. I'd report it as a bug if it meant it'd be fixed.