Posted 03 January 2013 - 11:11 AM
Computercraft: 1.48
Just spent an hour trying to figure out why peripheral.call(side, 'getID') kept returning nil. I could not find an answer on the wiki nor the forums. Eventually I figured it out when this call did succeed in lua mode…
Reproduction:
Place a computer, have it waiting for a 'peripheral' event. When this event arrives, call peripheral.call(side, 'getID') or alternatively local handle = peripheral.wrap(side) and then call handle.getID().
Place down another computer or turtle right next to the first one. The event will be triggered, which allows the code to continue. An attempt will be made to retrieve the ID for the computer/turtle you just placed down. The ID will be nil.
The reason for this is because the computer/turtle you just placed has not been activated yet. This happens automatically if you right click on it. As long as it is shut down, it will not respond until you turn it on first.
Suggestion:
Have the wiki clearly state that a computer or turtle will not respond to calls such as getID made using the peripheral API before the device has been turned on.
Alternatively, have these functions always succeed, regardless whether it has been turned on or not. getID should be considered pretty fundamental, since the ID is necessary for identification.
Workaround:
Call peripheral.call(side, 'turnOn') and then spin on a few ticks delay until peripheral.call(side, 'getID') returns something sane.
Edit:
More conforming with bug reporting guidelines to not look like a troll.
Just spent an hour trying to figure out why peripheral.call(side, 'getID') kept returning nil. I could not find an answer on the wiki nor the forums. Eventually I figured it out when this call did succeed in lua mode…
Reproduction:
Place a computer, have it waiting for a 'peripheral' event. When this event arrives, call peripheral.call(side, 'getID') or alternatively local handle = peripheral.wrap(side) and then call handle.getID().
Place down another computer or turtle right next to the first one. The event will be triggered, which allows the code to continue. An attempt will be made to retrieve the ID for the computer/turtle you just placed down. The ID will be nil.
The reason for this is because the computer/turtle you just placed has not been activated yet. This happens automatically if you right click on it. As long as it is shut down, it will not respond until you turn it on first.
Suggestion:
Have the wiki clearly state that a computer or turtle will not respond to calls such as getID made using the peripheral API before the device has been turned on.
Alternatively, have these functions always succeed, regardless whether it has been turned on or not. getID should be considered pretty fundamental, since the ID is necessary for identification.
Workaround:
Call peripheral.call(side, 'turnOn') and then spin on a few ticks delay until peripheral.call(side, 'getID') returns something sane.
Edit:
More conforming with bug reporting guidelines to not look like a troll.