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

[1.4.6][SMP/SSP][NotABug]peripheral.getID() does not function when target is inactive

Started by xtremeqg, 03 January 2013 - 10:11 AM
xtremeqg #1
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.
Cloudy #2
Posted 03 January 2013 - 11:59 AM
TL;DR - not a bug, the computer does not have an ID until it is activated.

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.

Request wiki edit access and do it yourself?

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.

Until you turn on the computer for the first time, the computer does not have an ID - therefore that call cannot succeed. We do not plan to change this any time soon - there's just no point in having it have an ID until it is activated.
MudkipTheEpic #3
Posted 03 January 2013 - 01:04 PM
–removed(saw end of OP)–
xtremeqg #4
Posted 04 January 2013 - 11:03 PM
TL;DR - not a bug, the computer does not have an ID until it is activated.

Undefined behavior is a bug until specified to be intended behavior. I could not find any mention anywhere that a computer has no ID until turned on. The only hit on Google is this very thread.

Request wiki edit access and do it yourself?

Done.

Until you turn on the computer for the first time, the computer does not have an ID - therefore that call cannot succeed. We do not plan to change this any time soon - there's just no point in having it have an ID until it is activated.

Acceptable, I plan to place that exact sentence on the wiki so others do not have to waste time.
Cloudy #5
Posted 04 January 2013 - 11:36 PM
Glad its all sorted!