58 posts
Posted 01 February 2013 - 04:19 PM
I'm trying to use CC to control a Command Block and send various commands in a large project I'm working on. But even though I enabled them in the server.properties and the ComputerCraft.cfg files, I get a "attempt to index ? a nil value"
Here's the offending code:
local modemside = "back" --side with the modem on it
local commandside = "right" --side with command block
local noteside = "bottom" --side with iron note block
mon = peripheral.wrap("top") --aquires monitor object
mX, mY = mon.getSize() --gets size of monitor
note = peripheral.wrap(noteside) --get note block for beeps
cmd = peripheral.wrap(commandside)
--start test code
mon.clear()
mon.setCursorPos(1,1)
mon.write("Lets test output to the command block!")
cmd.runCommand("/say this is a test of the command block interface") --this gives me an error
cmd.setCommand("/say this is a test of the command block interface") --ditto
local pwrap = fs.open("pwrap.txt", "w")
for k, v in pairs(cmd) do pwrap.writeLine(tostring(k)) end
pwrap.close() --pwrap.txt is empty!
Its like the .runCommand and .setCommand is never loaded from the peripheral.
What should I try next?
68 posts
Posted 01 February 2013 - 05:30 PM
I didn't know the vanilla command block behaved like a peripheral. Are you sure you don't need something else?
2088 posts
Location
South Africa
Posted 01 February 2013 - 05:37 PM
use peripheral.getMethods(cmd) to get the methods of it and then write it to a file
7508 posts
Location
Australia
Posted 01 February 2013 - 05:50 PM
@TheArchitect: yes they can, but they need to be enabled in the CC config to be able to
@TheGeek: Are you playing SMP? If so you need to enable the command block in server.properties
758 posts
Location
Budapest, Hungary
Posted 01 February 2013 - 06:35 PM
Keep in mind that command blocks are a bit buggy at the moment…
Take a look at this topicCommand blocks have three methods:
cmd.setCommand(command)
cmd.runCommand()
cmd.getCommand()
I think they're self explaining.
68 posts
Posted 01 February 2013 - 06:59 PM
@TheArchitect: yes they can, but they need to be enabled in the CC config to be able to
I haven't seen this mentioned in the wiki. Could you tell me where I can read more on this?
7508 posts
Location
Australia
Posted 01 February 2013 - 07:03 PM
@TheArchitect: yes they can, but they need to be enabled in the CC config to be able to
I haven't seen this mentioned in the wiki. Could you tell me where I can read more on this?
Ummmm idk if there is any documentation on it. I discovered it by accident. If you open ComputerCraft.cfg there is an "enableCommandBlock" or something like that, if you change the false to true then it can be interacted with like a peripheral with the functions LBPHacker stated.
And I know in SMP you also need to enable command blocks in the server.properties file
1111 posts
Location
Portland OR
Posted 01 February 2013 - 07:15 PM
I don't think you need the / in the function call
cmd.setCommand("/say this is a test of the command block interface")
--should probably be
cmd.setCommand("say this is a test of the command block interface")
2088 posts
Location
South Africa
Posted 01 February 2013 - 09:17 PM
You can have the / or not, makes no difference
58 posts
Posted 02 February 2013 - 05:44 AM
But even though I enabled them in the server.properties and the ComputerCraft.cfg files, I get a "attempt to index ? a nil value"
Yes I enabled them in both the server.properties and the ComputerCraft.cfg files.
I even attempted to get the methods of the peripherial and the file it generated was blank.
Its like the API for the command block isn't being loaded.
157 posts
Posted 27 April 2014 - 07:31 PM
Ermm, my issue was that it was the wrong side, perhaps your command block isn't being read, try replacing the command block maybe? Check your sides?