Difference between revisions of "CommandBlock.runCommand"

From ComputerCraft Wiki
Jump to: navigation, search
(Added commandBlock.runCommand)
 
(Fixed return parameters, improved example)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
{{Function
 
{{Function
|name=commandBlock.runCommand
+
|name=''commandBlock''.runCommand
 
|api=Command Block
 
|api=Command Block
|returns={{type|nil}}
+
|returns={{type|boolean}} success [<nowiki/>, {{type|string}} error]
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Runs the command inside the Command Block previously set by manually editing it or by using [[commandBlock.setCommand]]()
+
|desc=Runs the command inside the Command Block previously set by manually editing it or by using [[commandBlock.setCommand|''commandBlock''.setCommand]](). In case of error, returns <var>false</var> + an error message <var>error</var>.
 
|examples={{Example
 
|examples={{Example
 
|desc=Sets the command to ''toggledownfall'' and runs it (assuming the Command Block is on the left of the [[Computer]]).
 
|desc=Sets the command to ''toggledownfall'' and runs it (assuming the Command Block is on the left of the [[Computer]]).
|code=local commandBlock = [[peripheral.wrap]]("left")<br/><br/>[[commandBlock.setCommand]]("toggledownfall")<br/>commandBlock.runCommand()
+
|code=local commandBlock = [[peripheral.wrap]]("left")
 +
 +
[[commandBlock.setCommand]]( "toggledownfall" )
 +
'''commandBlock.runCommand()'''
 
}}
 
}}
 
}}
 
}}
  
 
[[Category:Lua_Core_Functions]]
 
[[Category:Lua_Core_Functions]]

Latest revision as of 19:29, 16 February 2015

Grid Redstone.png  Function commandBlock.runCommand
Runs the command inside the Command Block previously set by manually editing it or by using commandBlock.setCommand(). In case of error, returns false + an error message error.
Syntax commandBlock.runCommand()
Returns boolean success [, string error]
Part of ComputerCraft
API Command Block

Examples

Grid paper.png  Example
Sets the command to toggledownfall and runs it (assuming the Command Block is on the left of the Computer).
Code
local commandBlock = peripheral.wrap("left")

commandBlock.setCommand( "toggledownfall" )
commandBlock.runCommand()