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

peripheral.wrap returning nil, 1.58/ftb monster

Started by viveleroi, 19 April 2014 - 07:36 AM
viveleroi #1
Posted 19 April 2014 - 09:36 AM
When I place an advanced computer, and a wireless modem on top, the examples in the wiki that wrap the modem return nil:

local modem = peripheral.wrap("top")
modem.open(426)

The modem variable prints as nil, and this code throws an error.

However,
peripheral.call("top", "open",5)

works fine - the modem shows the red signal.

What am I doing wrong?
CometWolf #2
Posted 19 April 2014 - 03:36 PM
Im guessing your doing this in the console. If you localize a variable in the lua console, it will be local to that input

> local derp = "test"
> print(derp)
nil
>

> derp = "test"
> print(derp)
test
>
The wiki examples are probably meant for use within programs.
viveleroi #3
Posted 19 April 2014 - 05:33 PM
Thanks, but I've tried this in both the lua console, and in a script. I ran "edit myfile", wrote the code, saved, and then ran the file. Is there a better way?
CometWolf #4
Posted 20 April 2014 - 08:40 PM
So, putting this in a file

local modem = peripheral.wrap("top")
modem.open(426)
and running it, causes "an attempt to index nil value" error?
I don't think i've ever seen such behavior, are you doing this on a fresh computer, and could you possible provide some pictures?