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

Peripheral events (attach and deattach) - weird behaviour

Started by Deadlock989, 17 August 2015 - 12:07 PM
Deadlock989 #1
Posted 17 August 2015 - 02:07 PM
Hi all,

I'm experienced great weirdness with peripheral events in CC 1.74. I also have OpenPeripherals installed.

I'm looking out for peripherals being added and removed with a main event listener like this:


function paddlistener()
  local event, side = os.pullEvent("peripheral")
  printdebug("Peripheral added: "..side)
end

function premovelistener()
  local event, side = os.pullEvent("peripheral_detach")
  printdebug("Peripheral removed: "..side)
end

-- main loop
while true do
  parallel.waitForAny(mainlistener, paddlistener, premovelistener)
end

What happens when you add or remove nearby blocks from the computer, however, is more or less random madness. Or so it seems. Have I misunderstood what these events do?

One of two things will happen. Let's say I have a computer with a modem on top, two peripherals on the back and right. If I add something to the left, one of two things will happen. Either there will be up to SEVEN events fired - usually something like four adds ("peripheral") and three removes ("peripheral_detach") from several sides, usually right and left. Other times, I get the following:


Java Exception Thrown: 
You are not connected to this Computer

It is starting to look like a bug but I am new to peripherals so not sure. Can anyone help?
Lyqyd #2
Posted 17 August 2015 - 06:32 PM
Moved to Peripherals Help & Discussion.

This behavior is generally caused by a poorly implemented IPeripheral interface on the peripherals involved–most commonly, an IPeripheral equals() that returns false when it shouldn't.
Deadlock989 #3
Posted 17 August 2015 - 10:17 PM
Thank you Lyqyd. I saw a very similar comment on my search around the 'net for this issue.

I'll try it with machines from a wider variety of mods.