This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sxw's profile picture

[Api] [Cc 1.5+] Flow, The Next Generation Turtle Library - Pathfinding!

Started by Sxw, 30 July 2013 - 10:36 AM
Sxw #1
Posted 30 July 2013 - 12:36 PM
Flow is a turtle library that tracks positions, stores waypoints, and pathfinds to wherever you want to go.

Setup
SpoilerMake sure to load flow on every startup so the position is accurate.
When you first load flow, you will need to set the position with
flow.setPos(x, y, z, f)
Make sure to set these correctly by using F3 to find where.

Usage
SpoilerYou can continue running your programs as normal, because flow overwrites the turtle API.
If you want to take advantage of the pathfinding features, either set waypoints or store positions.

Waypoints
SpoilerSet a waypoint with
flow.setWaypoint(name, [x, y, z])
If x, y, and z are omitted, the turtles current position will be used.

Goto a waypoint with
flow.gotoWaypoint(name)
This will pathfind to the waypoint. Note that the turtles rotation will not be stored, so make sure you turn the right direction.
This will return a boolean value, success.

Pathfind to position
SpoilerPathfind to a point with
flow.pathfind(x, y, z)
This will return a boolean value, success.

Full docs
Spoilerflow.update([file]) - Updates flow to the latest release. Recommended to run on startup.
flow.wander(moves) - Wanders around for x moves.
flow.reset(sure) - Resets map, waypoints, and position if sure is true.
flow.getWaypoints() - Returns an array of waypoints
flow.delWaypoint(name) - Removes waypoint by name
flow.gotoWaypoint(name) - Goes to waypoint by name
flow.setWaypoint(name, [x, y, z]) - Sets a waypoint by name
flow.pathfind(x, y, z) - Attempts to pathfind to the given point
flow.face(face) - Faces face(0, 1, 2 or 3)

flow.setMapping(domap) - Sets mapping or not. Recommended to keep on so the turtle will learn faster. Basic mapping is a fast process. Mapping is enabled by default.
flow.setAdvMapping(doadvmap) - Sets advanced mapping. Recommended to keep on for a while when starting. Advanced mapping is disabled by default.

Download
SpoilerPastebin: http://pastebin.com/b4NusRJk
Github: https://github.com/S...lob/master/flow
Bugs: https://github.com/S...programs/issues

Credits for pathfinding go to TehPers for his awesome API.
jesusthekiller #2
Posted 30 July 2013 - 01:07 PM
and pathfinds to wherever you want to go.

Sounds sweet :)/>
Firnagzen #3
Posted 06 August 2013 - 09:24 AM
I've just tried this out with a test program, but I'm having an error.

os.loadAPI("flow")
flow.setPos(0,0,0)
flow.setWaypoint("home")
flow.setWaypoint("there", 1, 7, 9)
if flow.pathfind(2, -5, 1) then
  print("yes")
end
if flow.gotoWaypoint("there") then
  print("yes2")
end
turtle.forward()

This throws me an error flow:93: table index expected, got nil. There is no motion.

Removing turtle.forward() removes there error, but once again, there is no motion.

I'm using the version from pastebin, and I'm on computercraft 1.5.
Sxw #4
Posted 14 August 2013 - 07:00 PM
I've just tried this out with a test program, but I'm having an error.


flow.setPos(0,0,0)
-snip-
-snip-
flow.setPos takes 4 arguments, x, y, z, and facing. I'll make the error messages better.
Firnagzen #5
Posted 17 August 2013 - 09:41 AM
flow.setPos takes 4 arguments, x, y, z, and facing. I'll make the error messages better.
…Oops. My bad, thanks.
MegaThorx #6
Posted 23 August 2013 - 09:51 PM
I 've tried the following code without any results (no moving)


flow.setWaypoint("home")
flow.setWaypoint("there", 1, 7, 9)
if flow.pathfind(2, -5, 1) then
  print("yes")
else
print("false1")
end
if flow.gotoWaypoint("there") then
  print("yes2")
else
print("false2")
end

Spoiler

Please help me
Sxw #7
Posted 24 August 2013 - 01:18 AM
@MegaThorx
Have you mapped these areas? (as in the turtles has been there in a path accessible to flow)
Did you set the position correctly?
I plan to make unmapped path finding work, but now it has to be mapped.