Returning from point and returning empty array from C++ if no path found.
This commit is contained in:
@@ -56,13 +56,9 @@ func is_blocked(point: Vector2i) -> bool:
|
||||
return (_astar.get_terrain(point) == MultilevelAStarEx.BLOCKED) or _astar.get_unit(point)
|
||||
|
||||
|
||||
# returns a list of points containing the path (including the starting point) or an empty array if no path was found
|
||||
func find_path(from: Vector2i, to: Vector2i, return_closest: bool = false) -> Array[Vector2i]:
|
||||
assert(_used_rect.has_point(from))
|
||||
assert(_used_rect.has_point(to))
|
||||
|
||||
var res = _astar.find_path(from, to, return_closest) # returns Variant: null or Array[Vector2i]
|
||||
|
||||
if res != null:
|
||||
return res
|
||||
else:
|
||||
return []
|
||||
return _astar.find_path(from, to, return_closest)
|
||||
|
||||
@@ -61,10 +61,10 @@ func find_path() -> void:
|
||||
|
||||
var arr = astar.find_path(from, to, check_box.button_pressed) # vrne Variant: null ali Array
|
||||
#print(arr)
|
||||
print(arr.size())
|
||||
|
||||
if arr.size() > 0:
|
||||
if arr.size() > 1: # if the start and the end are the same there is no line to draw
|
||||
# add new path
|
||||
path_line.add_point(from * CELL_SIZE + Vector2i(16, 16))
|
||||
for vec in arr:
|
||||
#print("%s, %s" % [vec.x, vec.y])
|
||||
path_line.add_point(vec * CELL_SIZE + Vector2i(16, 16))
|
||||
|
||||
Reference in New Issue
Block a user