Difference between revisions of "Commands.getBlockInfo"

From ComputerCraft Wiki
Jump to: navigation, search
(Added a more straightforward example)
Line 18: Line 18:
  
 
|examples=
 
|examples=
 +
{{Example
 +
|desc=Prints the facing of the [[Command Computer]] running the script by inspecting its own metadata.
 +
|code=local blockInfo = '''commands.getBlockInfo( [[commands.getBlockPosition]]() )'''
 +
 +
[[print]]( "Computer block's name: ", blockInfo.name )
 +
[[print]]( "Computer block's metadata: ", blockInfo.metadata )
 +
}}
 
{{Example
 
{{Example
 
|desc=Prints the facing of the [[Command Computer]] running the script by inspecting its own metadata.
 
|desc=Prints the facing of the [[Command Computer]] running the script by inspecting its own metadata.
 
|code=local directions = {"unknown", "north", "south", "west", "east"}
 
|code=local directions = {"unknown", "north", "south", "west", "east"}
  local info = commands.getBlockInfo( [[commands.getBlockPosition|commands.getBlockPosition()]] )
+
  local blockInfo = '''commands.getBlockInfo( [[commands.getBlockPosition]]() )'''
  print( "My facing is ", directions[ info.metadata ], "." )
+
   
 +
[[print]]( "My facing is ", directions[ blockInfo.metadata ], "." )
 
}}
 
}}
 
}}
 
}}

Revision as of 15:01, 16 February 2015


Grid Redstone.png  Function commands.getBlockInfo
Available only to Command Computers, returns a table containing information on the block at the specified world co-ordinate, formatted as follows:
{
  name = string block's name,
  metadata = number block's metadata
}

The block inspected will be in the same dimension as the computer. This function yields until the data is available to be returned. If the queried block exists in an ungenerated chunk, this function will cause that chunk to be generated.

See also: Data Values @ MineCraft wiki
Syntax commands.getBlockInfo(number x, number y, number z)
Returns table block info
Part of ComputerCraft
API commands

Examples

Grid paper.png  Example
Prints the facing of the Command Computer running the script by inspecting its own metadata.
Code
local blockInfo = commands.getBlockInfo( commands.getBlockPosition() )

print( "Computer block's name: ", blockInfo.name )
print( "Computer block's metadata: ", blockInfo.metadata )



Grid paper.png  Example
Prints the facing of the Command Computer running the script by inspecting its own metadata.
Code
local directions = {"unknown", "north", "south", "west", "east"}
local blockInfo = commands.getBlockInfo( commands.getBlockPosition() )

print( "My facing is ", directions[ blockInfo.metadata ], "." )


Grid disk.png Commands API Functions
commands.exec - commands.execAsync - commands.list - commands.getBlockPosition - commands.getBlockInfo - commands.getBlockInfos