Difference between revisions of "Gps (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Added examples of rednet entities)
Line 1: Line 1:
The gps API provides a method to locate a connected [[Rednet_(API)|rednet]] entity (like a turtle or a computer).
+
The gps API provides a method for turtles and computers to get their own locations.
  
 +
It broadcasts a PING message over [[Rednet_(API)|rednet]] and wait for responses. In order for this system to work, there must be computers used as gps ''hosts'' which will respond and allow [https://en.wikipedia.org/wiki/Triangulation triangulation].
 +
  
 
{| border="1" cellpadding="2" cellspacing="0"
 
{| border="1" cellpadding="2" cellspacing="0"
Line 7: Line 9:
 
|-
 
|-
 
|gps.locate(timeout, debug)
 
|gps.locate(timeout, debug)
|Tries to locate any connected rednet entity.<br />
+
|Tries to retrieve the computer or turtle own location.<br />
 
''@param'' '''timeout''' the amount of time, in seconds, to wait for a rednet response<br />
 
''@param'' '''timeout''' the amount of time, in seconds, to wait for a rednet response<br />
 
''@param'' '''debug''' if true, outputs debug messages<br />
 
''@param'' '''debug''' if true, outputs debug messages<br />
''@return'' the location of the connected rednet entity (x, y and z) or nil if it could not be determined
+
''@return'' the computer or turtle own location (x, y, z) or nil if it could not be determined
 
|}
 
|}
  
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 21:54, 14 March 2012

The gps API provides a method for turtles and computers to get their own locations.

It broadcasts a PING message over rednet and wait for responses. In order for this system to work, there must be computers used as gps hosts which will respond and allow triangulation.


Method name Description
gps.locate(timeout, debug) Tries to retrieve the computer or turtle own location.

@param timeout the amount of time, in seconds, to wait for a rednet response
@param debug if true, outputs debug messages
@return the computer or turtle own location (x, y, z) or nil if it could not be determined