GetPath

Category: Landscape
Since engine version: 4.9.10.7 [334] LC

Description

Searches for a path from start point to end point using the pathfinding algorithm as used by clonks and returns a map with its waypoints and length. Returns nil if no path was found. The returned map is structured like this:
Key Data type Description
Length int Length of the found path, same as returned byGetPathLength
Waypoints array Array containing waypoints
The waypoints are structured like this:
Key Data type Description
X int X coordinate of the waypoint
Y int Y coordinate of the waypoint
TransferTarget object Transfer target. only set if present.

Syntax

map GetPath (int iFromX, int iFromY, int iToX, int iToY);

Parameters

iFromX:
X coordinate of the starting position
iFromY:
Y coordinate of the starting position
iToX:
X coordinate of the end position
iToY:
Y coordinate of the end position

Remark

This function can only be used with #strict 3 or above because of the map syntax. Use GetPathLength in older versions.

Example

var path = GetPath(GetX(), GetY(), GetX(FindBase(GetOwner())), GetY(FindBase(GetOwner())));
if (path)
{
    Log("Anzahl der Wegpunkte: %d, Pfadlänge: %d", GetLength(path.Waypoints), path.Length);
}
else
{
    Log("Kein Pfad gefunden!");
}
        
Logs the number of waypoints and the path length to the calling object's owner's first base, if a way has been found.
See also: GetPathLength
Fulgen, Oktober 2019