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

MagicTurtle v1.38 - Pathfinding! Mapping! Exploration!

Started by EatenAlive3, 27 May 2012 - 12:17 PM
EatenAlive3 #1
Posted 27 May 2012 - 02:17 PM
Hi all. Originally, I found Liraal's MagicTurtle API and started improving on it, and then we started working together. Eventually, I suppose he lost interest, but he did give me permission to post this as my own API. I haven't worked on this in a while, so it is still in the beta stage for a few features, like unmapped pathfinding, although it does work for the most part. Anyway, full feature list below in spoilers, but here are some of the highlights:

> The turtle will record data through a mapping system as it travels; it remembers where it's been and what blocks were there.
> The turtle is able to explore portions of land fairly quickly.
> Turtles are now able to pathfind to given coordinates, so long as it has mapped the area for it.
> …if the area has not been mapped, it will do its best to get there.
> Ability to render a map of what's been explored, or a given coordinate.
> Tons of features that really should be in turtles, like place(cobblestone), forward(5), or select(wood).
> Tons of even more cool features that make it so you will never have to worry about turtle functions again!

SpoilerLoading functions:
Spoiler

-main() - runs at start of program as setup.
-load() - loads all saved data.
-save() - saves all data.
-saveSlots() - saves all slot data.
-loadSlots() - loads all slot data.
-updateSlots() - makes changes to slots if changes have occurred.
-version() - returns magicturtle version
-savePos() - saves position data
-getPosF() - loads position data

Setup functions:
Spoiler

-setPos(x,y,z[,face]) - sets the coordinates of the turtle to x,y,z, and optionally direction to face.
-setNorth() - run this if turtle is in fact facing north, and does not yet know its direction.
-setFacing(face) - sets the direction of the turtle to face, a number between 0 and 3. Find this by
hitting F3 and looking under coordinates, f:(number)
-setSlot(slotnumber,block) - sets the specified slot number to the specified block. ex: setSlot
(1,dirt)

Movement functions:
Spoiler

-faceSouth(),faceEast(),faceNorth(),faceWest() - faces the turtle in the direction.
-faceSet(direction) - turns turtle to face the direction, being a number 0-3
-turnLeft([times]) - turns left, and if specified, the number of times.
-turnRight([times]) - turns right, optionally the number of times.
-rotate(times) - rotates counterclockwise to the most efficient angle. Takes a number 0 or higher.
-up([times]) - makes the turtle move up, number of times.
-down([times]) - makes the turtle move down, number of times.
-forward([times]) - makes the turtle move forward, number of times.
-back([times]) - makes the turtle move back, number of times.
-left([times]) - makes the turtle MOVE (not turn) left, number of times.
-right([times]) - makes the turtle move right, number of times.
-goToPos(x,y,z,mode) - a quicker but less effective pathfinding algorithm; it works in open space
only, unless mode is set to true, in which it will break blocks to get to its destination.
-road() - turtle follows a road of redstone torches.
-wander() - wanders slowly about the landscape.
-wanderer(function) - executes the function while wandering about the landscape.
-path(direction) - simple pathfinding function for mazes, does not utilize mapping.
-goDirection(direction,spaces) - turtle goes in direction, for spaces. Direction is a number 0-5.
-pathfind(x,y,z) - using the A* pathfinding algorithm, pathfinds to the given coordinates.

Block manipulation functions:
Spoiler

-tunnel(width,height,length) - digs a tunnel of the specified dimensions.
-staircase(width,height,length) - digs a staircase of the specified dimensions.
-place(block) - places the block from the turtle's inventory, or slotnumber if a number is used.
-placeUp(block), placeDown(block) - same as place, up and down.
-dig([block]) - if block is specified, turtle will dig the specific block. Otherwise, turtle will dig.
-digUp([block]),digDown([block]) - up and down.
-build(blueprint) - builds a design from the specified blueprint, which are created with sketch().
-sketch() - allows the user to create a blueprint, to save and build later.
-patch(slot, length, width) - patches holes in the ground using the block in slot, of length and
width.
-architect(width, height, length) - destroys a building to make a blueprint of it.
-replace(block1,block2) - replaces block1 with block2, if block1 is in front of the turtle.
-replaceUp(b1,b2),replaceDown(b1,b2) - up and down.

Resource-gathering functions:
Spoiler

-jack(slot) - plants, watches and cuts down a single tree (slot is the slot with saplings)
-treefarm(slot) - preforms jack() in a continuous loop.
-mine(mode,length) - if mode is "diamond", creates diamond mine. If mode is "regular", then
creates a tunnel of length*length*length dimensions. If mode is "quarry", creates a quarry.

Inventory functions:
Spoiler

-getSelection() - returns the currently selected slot in turtle's inventory.
-getSlot(slotnumber) - returns the block ID of the slotnumber
-select(slotnumber) - selects the slotnumber in the turtle's inventory.
-isSpace() - returns true if there is space in turtle's inventory, false if not.
-getMatch(blocktype) - searches inventory for blocktype, returns slot number if in inventory or
false if not in inventory.
-drop(block) - drops the block specified, or slot number if a number is used as a parameter.

Position functions:
Spoiler

-getPos() - returns turtle x, y, and z coordinates.
-getFacing() - returns the direction the turtle is facing, 0-3.

Mapping functions:
Spoiler

-checkSides() - returns the front, right, back, left, top and bottom block states (true or false)
-checkSidesType() - returns the block IDs of front,right,back,left,top,bottom. Slower than
checkSides(), but more specific.
-detectLeft() - detects to the left of the turtle.
-detectRight() - detects to the right of the turtle.
-detectBack() - detects behind the turtle.
-detect(side) - takes side as a string, returns the value. ex: detect("left")
-detectDir(face) - takes a number 0-3, returns the value. ex: detectDir(3)
-mapSides() - checks the sides around the turtle, and records block data to mapping. mapSides
is faster than mapSidesType, because it does not need to use compare()
-mapSidesHorizontal(), mapSidesVert() - maps sides horizontally and vertically, faster but covers
less ground.
-mapSidesType() - checks sides around turtle, records block data. More specific block data, but
slower than mapSides. All type functions are slower.
-mapSidesTypeHorizontal(),mapSidesTypeVert() - horizontal and vertical, faster.
-getCoordCount(coord,value) - coord is "x","y", or "z". This function returns the amount of
coordinates on the x/y/z axis with the value. ex: getCoordCount("y",64) returns the number of
coordinates on the Y axis with the value of 64.
-dist(x1,y1,z1,x2,y2,z2) - returns the distance between two points.
-getClosest(x,y,z,radius,type) - returns a table containing the closest block of type within the
radius, with a maximum radius of 20. Usually the table contains one element, but sometimes,
two or more blocks are the same distance apart, hence returning a table.
-explore(radius[,goback[,mode]]) - turtle will explore blocks exposed to air within radius of itself.
If goback is set to true, the turtle will return to the coordinates it was at when it started the
search. If mode is set to true, then a percentage bar will appear, showing the progress of the
search.
-exploreType(radius[,goback[,mode]]) - explores block types exposed to air within the radius.
-exploreSel(x1,y1,z1,x2,y2,z2[,goback[,mode]]) - explores the selection in a cuboid from point1
to point2.
-exploreTypeSel(x1,y1,z1,x2,y2,z2[,gobackp,mode]]) - explores the block types within the
selection, from point1 to point2.

Block data functions:
Spoiler

-getBlock(x,y,z) - returns the block at x, y, and z. use getBlockName(getBlock(x,y,z)) if a name is
required, otherwise returns the block ID.
-setBlock(x,y,z,blocktype) - sets the block at x, y, z to the blocktype. Type can be a block name
or ID.
-getBlockName(id) - returns the name of the block ID. ex: getBlockName(20) >>glass
-getBlockID(name) - returns the ID of the block name ex: getBlockID(glass) >>20
-compare(slot),compareUp(slot),compareDown(slot) - uses turtle.compare() to a slot.
-compareAll(),compareAllUp(),compareAllDown() - compares all slots, returns 9 booleans.
-getSlotMatch(s1,s2,s3,s4,s5,s6,s7,s8,s9) - takes a set of nine boolean states after doing a
compareAll()/compareAllUp()/compareAllDown(), and returns the slot number of the first slot
that matches the compare. ex: getSlotMatch(compareAll()) if sand is in the fifth slot, and
the block in front is sand, then 5 will be returned.
getBlockName(getSlot(getSlotMatch(compareAll()))) would return "sand" in that case.
-getRow(blocktype,x1,y1,z1,x2,y2,z2) - returns how many blocks of blocktype, starting at
x1,y1,z1 as a source block, continue in a row towards x2,y2,z2. No diagonals, just cardinal
directions and up/down.
-getBorderingBlocks(x,y,z) - returns the north,east,south,west,up and down block IDs of x,y,z.
-getBlockTypeDirection(blocktype,block1,block2,b3,b4,b5,b6) - After doing a
getBorderingBlocks(), using this function will return what direction that blocktype is in.
ex: getBlockTypeDirection(air,getBorderingBlocks(5,64,-3)) will return what direction that air is
in from 5,64,-3. Useful for many things, such as pathfinding, exploring, etc.
-getFullRow(x1,y1,z1,x2,y2,z2) - returns a table containing all the blocks within x1,y1,z1,x2,y2,z2
Works in cardinal directions and up/down only.
-graph(x,y,z[,width[,height[,mode]]]) - graphs the surroundings around x,y,z. Optional: Width,
height, and mode: width/height set the size, mode sets 'fancy graphics'; blocks that are air and
have a block below them will be rendered as a '=' sign, but it takes twice as long to render
(although the render time is virtually zero.)
-getBlockInDir(x,y,z,direction) - gets the block ID that is one space in the direction.
-getCoordInDir(x,y,z,direction,spaces) - gets the coordinate that is spaces from x,y,z in direction.
-getCube(x,y,z,radius[,type]) - returns a table listing all the coordinates within a cubic radius of
x,y,z. If type is specified, only the coordinates that match type will be returned.
-getCubeSel(x1,y1,z1,x2,y2,z2[,type]) - returns a table listing all the coordinates in a cuboid
between point1 and point2. Again, if type is specified, only the coordinates matching type will
be returned.

Misc. functions:
Spoiler

-landmine(slot, net) - turtle buries itself in the ground and places TNT that is triggered when
something is placed on top of it. Can be armed/disarmed by rednet if net is set to true. (slot is
the slot containing TNT)
-guardArea(function,width,length) - patrols an area of width and length, and if it runs into an
obstacle/hole, triggers the function.
-mineGrid(slot) - makes a grid of TNT placed 1 block beneath surface
-setMineID(arming, disarming) - sets mine arming/disarming IDs (these are separate and can
differ from each other)
-setUpdateID(id) - sets the ID of remote control terminal
-getSeperated(string) - useful utility function, example use:
position = "56,52,-117"
w = getSeperated(position..",|")
x,y,z = w[1],w[2],w[3]
-blockToText(blockID) - returns " " if id = 0(air), "~" if id = 126(unmapped), "T" if block id is a
turtle id, "#" if block id is 3,12,13, or 18 (dirt,sand,gravel, or leaves), "i" if id = 50(torch), or "@" if
any other id. Used for graphing, or if you'd like to create custom graph functions.
-getDirection(x1,y1,z1,x2,y2,z2) - gets the cardinal or up/down direction from point1 to point2.
-goToCoordsPath(x,y,z) - Used only for pathfinding via waypoints – ONLY works if the
coordinate is one block away, not diagonally. This is useless unless you want to create a
pathfinding algorithm different from pathfind(x,y,z)

Prototypes:
Spoiler

The 'Vertex' prototype is currently outdated, I will update this when I finish 1.4
-Vertex:new() - creates a new Vertex.
-Prototype Vertex - used for pathfinding:
Spoiler

local x,y,z,ID,active = 0,0,0,0,true
getPos() - returns x,y,z
setID(number) - sets ID, required for path saving
getID() - returns ID
addPath(state) - adds a point to the path waypoint system, under the ID of the Vertex
getPath() - returns a table containing the path.
setActive(state) - sets the Vertex to active or inactive, boolean
isActive() - returns true if active, false if inactive
getPosString() - returns the position as a string
deletePath() - clears all path data



Feature list is to be updated in the near future.

Pastebin:
http://pastebin.com/Yt1u8zAu

If there is enough support for this, then I will go on to finish v1.4, and possibly more beyond that. v1.4 will streamline all code, and fix any bugs that may exist. I'm actually about 40% done with that so far. Post any questions, comments, or suggestions about the API in this thread.

Basic usage guide:
Spoiler1.) First, when you have installed the API, stand on top of your turtle and press f3.
2.) Open the Lua interpreter and type "mt.setPos(x,y,z)" where mt can be whatever you saved the API as, and x, y and z are your current positions. Remember to subtract 2 from the Y value, because your turtle is 2 blocks below you!
3.) Face the direction the turtle is facing, and look for the f: value on your f3 screen (probably below the z axis value). Type "mt.setFacing(f)" where f is the f value. Of course, mt being your API name.
4.) So that your turtle can get a basic idea of its surroundings, do "mt.explore(2)". This will build a map of the turtle's surroundings, with a radius of 2.
5.) For each inventory slot that is not empty in your turtle, it would help to do "mt.setSlot(slot#,itemName)" for each. Slot #s are 1-3 for the top, 4-6 for middle, 7-9 for bottom. The itemName can be any conventional item name, like "cobble" or "cobblestone". You will only have to register slots once.
6.) Now you are set for pretty much anything. Your turtle can tell the difference between torches and stone if it has either in its inventory, for example, with exploreType(). You can pathfind to already mapped space fairly quickly, and if you want a 2d map of any layer, use "mt.graph(x,y,z)" where x, y, and z are coordinates. Experiment with the commands, and have fun!

If you would like an example code, here is something that O.S. wrote, as a manual remote control for turtles using a modified graph function:
Spoiler

-- mCtrl - Manual Turtle Control
--
-- Instructions:
--  * Install MagicTurtle API (must be named 'mt')
--  * Set up Position and Facing
--  * Run mCtrl
--  * Use controls below to explore
--
-- Keys:
-- W,A,S,D = Movement (North, West, South, East)
-- R,F   = Up, Down (Vertically)
-- E	   = Break front block
-- X	   = Maps blocks around Turtle
-- C	   = Refuel (if fuel is needed)
-- 1,2,3,4 = Place block from that slot number
-- Q	   = Quit
os.loadAPI("mt")
local run = true
function update()
   local x,y,z = mt.getPos()
   local d = mt.getFacing()
 
   -- Draws the map first
   graph(x,y,z)
 
   -- Draws Coord at the top
   term.setCursorPos(1,1)
   term.write("("..x..","..y..","..z..")")
 
   -- Draws Turtle at the center (with direction)
   term.setCursorPos(20,6)
   if(d == 0) then
		  term.write("v")
   elseif(d == 1) then
		  term.write("<")
   elseif(d == 2) then
		  term.write("^")
   elseif(d == 3) then
		  term.write(">")
   end
 
   -- Draws Fuel (if fuel is needed)
   if(turtle.getFuelLevel() ~= "unlimited") then
		  term.setCursorPos(1,13)
		  term.write("Fuel: "..turtle.getFuelLevel())
   end
 
end
-- Copied and modified from MagicTurtle's code
-- Redone to remove term.clear(), makes the program look smoother. :-)
function graph(xs,ys,zs)
		 local curX,curZ = 1,1
		 local width,height = term.getSize()
		 width = width + 1
		 local xw,zw = math.floor(width/2),math.floor(height/2)
		 local fullRow = 0
		 local fullRowY = 0
		 local tmp = {}
		 local temp = {}
		 local tempp = 0
		 term.setCursorPos(1,1)
		 for i=1,height-1,1 do
		  fullRow = mt.getFullRow(xs-xw+curX,ys,zs-zw+curZ,xs+xw,ys,zs+zw)
		  for i=1,width-1,1 do
		   tmp = mt.getSeperated(fullRow)
		   tempp = mt.blockToText(tmp[i])
		   if mode then temp = mt.getSeperated(fullRowY)
		   if tempp == " " and mt.blockToText(temp[i]) ~= " " and mt.blockToText(temp[i]) ~= "~" then tempp = "=" end end
		   term.write(tempp)
		  end
		  if curZ <= height then
		   curZ = curZ + 1
		   term.setCursorPos(1,curZ)
		  else break end
		 end
    end
update() -- Draw inital map
while run do
   local event, p1, p2, p3, p4, p5 = os.pullEvent()-- Listen for key events
   if(event == "char") then
		  if(p1 == "q") then -- Quits out of the program and cleans the screen
				 run = false
				 term.clear()
				 term.setCursorPos(1,1)
		  elseif(p1 == "w") then -- Move North
				 mt.faceNorth()
				 mt.forward()
				 update()
		  elseif(p1 == "a") then -- Move West
				 mt.faceWest()
				 mt.forward()
				 update()
		  elseif(p1 == "s") then -- Move South
				 mt.faceSouth()
				 mt.forward()
				 update()
		  elseif(p1 == "d") then -- Move East
				 mt.faceEast()
				 mt.forward()
				 update()
		  elseif(p1 == "r") then -- Move Up
				 mt.up()
				 update()
		  elseif(p1 == "f") then -- Move Down
				 mt.down()
				 update()
		  elseif(p1 == "e") then -- Break block
				 mt.dig()
				 update()
		  elseif(p1 == "x") then -- Map all sides (Does not compare types)
				 mt.mapSides()
				 update()
		  elseif(p1 == "c" and turtle.getFuelLevel() ~= "unlimited") then -- Refuel (if needed)
				 for slot = 1, 16 do
				    local cnt = turtle.getItemCount(slot)
				    if(cnt > 0) then
						   turtle.select(slot)
						   if turtle.refuel(1) then
								  update()
								  break
						   end
				    end
				 end
		  elseif(p1 == "1" or p1 == "2" or p1 == "3" or p1 == "4") then -- Place block
				 mt.place(tonumber(p1))
				 update()
		  end
   end
end

Smarter turtles for a smarter future!

Enjoy!
professorloz #2
Posted 14 June 2012 - 02:07 AM
Total noob here so this'll probably sound like something really basic but here goes. I am trying to make a program that will go to a specific co-ordinate set given, e.g. 3,5,7 and then do a bunch of stuff, like dig down or place a TNT block etc, then return. Now I had a bit of trouble but so far I have this:


term.clear()
term.setCursorPos(1,1)
print("-------------------------")
print("Where am I [X]?:")
print("-------------------------")
a = io.read()
a = tonumber(a)
print("-------------------------")
term.clear()
term.setCursorPos(1,1)
print("-------------------------")
print("Where am I [Y]?:")
print("-------------------------")
b = io.read()
b = tonumber(-_-/>/>
print("-------------------------")
term.clear()
term.setCursorPos(1,1)
print("-------------------------")
print("Where am I [Z]?:")
print("-------------------------")
c = io.read()
c = tonumber(c)
print("-------------------------")
term.clear()
term.setCursorPos(1,1)
print("-------------------------")
print("Where am I going [X]:")
print("-------------------------")
d = io.read()
d = tonumber(d)
print("-------------------------")
term.clear()
term.setCursorPos(1,1)
print("-------------------------")
print("Where am I going [Y]:")
print("-------------------------")
e = io.read()
e = tonumber(e)
print("-------------------------")
term.clear()
term.setCursorPos(1,1)
print("-------------------------")
print("Where am I going [Z]:")
print("-------------------------")
f = io.read()
f = tonumber(f)
print("-------------------------")
term.clear()
term.setCursorPos(1,1)
print("-------------------------")
print("Setting position as:")
print("-------------------------")
print(a.. "," ..b.. "," ..c)
print("-------------------------")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("-------------------------")
print("Setting destination as:")
print("-------------------------")
print(d.. "," ..e.. "," ..f)
print("-------------------------")
sleep(1)
magic.setPos(a.. "," ..b.. "," ..c)
magic.goToPos(d.. "," ..e.. "," ..f)
magic.setPos(d.. "," ..e.. "," ..f)
magic.goToPos(a.. "," ..b.. "," ..c)

It seems to have a problem with the setPos and goToPos bit, I did a print of the destination and current position to make sure the output of the a.. "," ..b.. "," ..c and the d.. "," ..e.. "," ..f was in the right layout to function yet for some reason it doesn't like it. I suspect that the layout I have done only works for the print() function. Anyways any help making this work or remaking it or whatever would be helpful thanks :(/>/>

Also, it's magic.* as I named the api file as magic, also I've attempted to get it to return by grabbing the older location numbers and the destination numbers and simply swapping them. Also would I need to do this setNorth() stuff, it doesn't use the getPos() so I'm not sure if it does?

Thanks Again in advance :)/>/>

Kieran
Lyqyd #3
Posted 14 June 2012 - 06:33 PM
Yeah, you shouldn't be trying to concatenate those arguments into a string. Get rid of the quotes around the commas and the concatenation operators and it should work.
kazagistar #4
Posted 16 June 2012 - 07:33 AM
This is pretty beast. I am going to have to look into how you do stuff like architecting…
EatenAlive3 #5
Posted 17 June 2012 - 03:57 PM
Thanks! Yes, the architect system is pretty clever. I try to make turtles more useful by letting them collect as much information as they possibly can. The more they know, the more they can do!
maxostarr #6
Posted 02 July 2012 - 02:13 AM
when i try mt.setpos(x,y,z) i get "27: [string "lua"]:1: ')' expected". plz help
EatenAlive3 #7
Posted 07 July 2012 - 12:02 PM
Remember, Lua is case-sensitive. Use mt.setPos(), not mt.setpos.
rommels #8
Posted 10 July 2012 - 01:42 PM
Having a bit of an odd issue with the .pathfind(x,y,z) function in that it does not apear to work with the error "mt:2495: attempt to index ? (a nill value)" the command: mt.pathfind(89,64,243)

The alternative goToPos works, however as warned will not reach the destination if it comes accross an obsticle, the appropriate .setPos and .setFacing() have been set and the script is located in mt (/rom/apis)

any ideas?
MathManiac #9
Posted 14 July 2012 - 06:00 PM
@proffesorloz, rommels: Stop hijacking people's threads. Post your own thread at http://www.computercraft.info/forums2/index.php?/forum/14-ask-a-pro/


I'm having trouble with some of your spoilers. Some of them looks like they are three spoilers with one spoiler button, and I can't open them with the button.
maxostarr #10
Posted 20 July 2012 - 11:30 PM
Remember, Lua is case-sensitive. Use mt.setPos(), not mt.setpos.
thx from maxostarr
KyleBoyer #11
Posted 24 July 2012 - 09:33 AM
This is pretty nice, but I am completely lost at how to ge this setup, so I did this:
pastebin get Yt1u8zAu startup
It gets the script and installs it as "startup", then I start the script by saying "startup" and it says I need to set the position with setPos. How in the world do I set the Pos?
EatenAlive3 #12
Posted 03 August 2012 - 11:35 AM
Read in the original post, "Basic Usage guide." Don't worry, it isn't a long read!
Keaton #13
Posted 03 August 2012 - 03:57 PM
This is very interesting, and I was wondering if you could further explain how the mt.gotoPos works, it would be a really useful thing to include in something I am working on. Nuke dropping gps guided turtles is something I would love to get working on my friends server.


Also, does this work on a server if only one person has installed it, or does the server need to?
EatenAlive3 #14
Posted 03 August 2012 - 09:59 PM
It only matters that an ingame turtle has this installed, and then you can redistribute it to other computers via floppy-disks.
Keaton #15
Posted 03 August 2012 - 10:40 PM
Ok so put it into the turtles, but iv never seen the magic. commands, is there anything special about them or anything else i must do to make all of it work? and could i use mt.gotoPos outside of this specific program?
Pharap #16
Posted 08 August 2012 - 06:24 PM
Total noob here so this'll probably sound like something really basic but here goes. I am trying to make a program that will go to a specific co-ordinate set given, e.g. 3,5,7 and then do a bunch of stuff, like dig down or place a TNT block etc, then return. Now I had a bit of trouble but so far I have this:

It seems to have a problem with the setPos and goToPos bit, I did a print of the destination and current position to make sure the output of the a.. "," ..b.. "," ..c and the d.. "," ..e.. "," ..f was in the right layout to function yet for some reason it doesn't like it. I suspect that the layout I have done only works for the print() function. Anyways any help making this work or remaking it or whatever would be helpful thanks ;)/>/>

Also, it's magic.* as I named the api file as magic, also I've attempted to get it to return by grabbing the older location numbers and the destination numbers and simply swapping them. Also would I need to do this setNorth() stuff, it doesn't use the getPos() so I'm not sure if it does?

Thanks Again in advance :(/>/>

Kieran

You know you're supposed to start your own thread if you want to ask questions, right?
Hijacking other people's threads to ask questions isn't good.

@proffesorloz, rommels: Stop hijacking people's threads. Post your own thread at http://www.computerc...m/14-ask-a-pro/


I'm having trouble with some of your spoilers. Some of them looks like they are three spoilers with one spoiler button, and I can't open them with the button.

Give him a break, it's his first post.
Pharap #17
Posted 08 August 2012 - 06:25 PM
This is everything turtles should do and more. I support the project. In fact, if you ever need an extra pair of hands to help you, I'm prepared to help you out since I had an idea similar to this and it will help me out majorly with my planned turtle project.

I don't know how to make APIs and I'm still fairly new to lua (only been using it for about a week) but I have quite a bit of programming experience (I'm competent in VB, fairly good at C# and have dabbled in C++ as well as knowing the basics of html and css. And yes, I do know about object orientation) and I'm good at solving problems so if you do need help, I'd love to be able to contribute to a project like this.
EatenAlive3 #18
Posted 08 August 2012 - 06:59 PM
I'd love to hear your ideas, if you're willing to share them. Send me a PM if you want, and we might be able to code it in. Currently I am unable to improve the API because I've injured my left hand and want to keep it out of use, but I will return to the project soon and I'm open to ideas.
mynameisjpro #19
Posted 13 August 2012 - 09:59 AM
How do I connect this to a remote terminal? :P/>/> and run commands from the remote terminal. :S
EatenAlive3 #20
Posted 17 August 2012 - 02:09 PM
To connect this to a remote terminal, you would have to broadcast the messages from a central turtle/computer, and receive them from your target turtle.
funkey100 #21
Posted 26 August 2012 - 07:08 AM
I think this is awesome and should continue!
Lyqyd #22
Posted 29 August 2012 - 03:59 PM
I think this is awesome and should continue!

I've been poking at this API recently and have found quite a few improvements to make. I'm not quite ready to bring it to the two authors yet, but the code is being continually worked on!
linuxpro #23
Posted 04 September 2012 - 07:40 AM
I have a program that i made to have my turtles go to a given pos but no logic for if it gets stuck.

I was hopping you could tell me what functions in your code handles this kind of events so I can get some ideas how to move the turtle to get unstuck.

thanks
linuxpro
sneezing panda #24
Posted 04 September 2012 - 10:36 PM
Hi, I am getting "lua:1: attempt to index ? (a nil value)" when I run "mt.setPos(-61,63,1526)" Any idea why?
Lyqyd #25
Posted 05 September 2012 - 01:47 AM
Do you have the file saved as "mt", no file extension? Did you load the file as an API, or is it in the APIs folder?
EatenAlive3 #26
Posted 16 September 2012 - 04:52 PM
You have to use type it using the filename you specify, if you're using it as an API. If you're just running it, use setPos() instead of mt.setPos().
Starwaster #27
Posted 29 September 2012 - 06:11 AM
The version function doesn't work; attempts to call it result in 'attempt to call nil'

The reason is that functions can't share the same name as any variables. (i.e. you can't have a function named version because you already have a variable by that name)

(yeah I know it's not a huge bug but I thought it might be worth knowing)

Oh, and hi all. Love the mod, API looks cool too.
MysticT #28
Posted 30 September 2012 - 12:00 AM
The version function doesn't work; attempts to call it result in 'attempt to call nil'

The reason is that functions can't share the same name as any variables. (i.e. you can't have a function named version because you already have a variable by that name)

(yeah I know it's not a huge bug but I thought it might be worth knowing)

Oh, and hi all. Love the mod, API looks cool too.
Well, the version variable is local, while the version function is global, so there should be no problem. Not sure why you get that error though.
Starwaster #29
Posted 05 October 2012 - 10:16 AM
The version function doesn't work; attempts to call it result in 'attempt to call nil'

The reason is that functions can't share the same name as any variables. (i.e. you can't have a function named version because you already have a variable by that name)

(yeah I know it's not a huge bug but I thought it might be worth knowing)

Oh, and hi all. Love the mod, API looks cool too.
Well, the version variable is local, while the version function is global, so there should be no problem. Not sure why you get that error though.

Doesn't matter whether it's global or local. It's a naming restriction. Names (or identifiers in lua) are used for the same purpose in variables OR functions. Once it's declared for something, you can't then turn around and reuse the name for something else.

Renaming the variable eliminates the issue. (which, understand, it's not a huge issue; I doubt anyone out there was depending on the version function for something critical, I only posted as an FYI to the OP and to anyone else who might come across this post)
MysticT #30
Posted 06 October 2012 - 02:09 AM
The version function doesn't work; attempts to call it result in 'attempt to call nil'

The reason is that functions can't share the same name as any variables. (i.e. you can't have a function named version because you already have a variable by that name)

(yeah I know it's not a huge bug but I thought it might be worth knowing)

Oh, and hi all. Love the mod, API looks cool too.
Well, the version variable is local, while the version function is global, so there should be no problem. Not sure why you get that error though.

Doesn't matter whether it's global or local. It's a naming restriction. Names (or identifiers in lua) are used for the same purpose in variables OR functions. Once it's declared for something, you can't then turn around and reuse the name for something else.

Renaming the variable eliminates the issue. (which, understand, it's not a huge issue; I doubt anyone out there was depending on the version function for something critical, I only posted as an FYI to the OP and to anyone else who might come across this post)
Well, it turns out that the local variable was the problem, but not for what you said. You can have all the variables you want with the same name if they are in a different scope. The problem is that the version variable is defined and assigned a values, then it's overwrited with the function, but it's still local, so os.loadAPI can't "see" the function.
Anyway, not a big deal, it's just a version check that most people probably won't use :(/>/>
ikon106 #31
Posted 09 October 2012 - 08:54 PM
Could you post a mirror? I don't want to use pastebin :P/>/>
Pharap #32
Posted 13 October 2012 - 04:23 AM
Could you post a mirror? I don't want to use pastebin :)/>/>
what's wrong with pastebin?
ChunLing #33
Posted 13 October 2012 - 05:09 PM
I think that Homeland Security puts you on a watch list if you visit the site.
Pharap #34
Posted 14 October 2012 - 08:43 PM
I think that Homeland Security puts you on a watch list if you visit the site.
Then delete your cookies and use proxies.
ChunLing #35
Posted 15 October 2012 - 06:22 AM
Oh, but I'm already on the "Target of opportunity" (AKA "Kill if you have plausible deniability") list, so I'm not worried about the watch lists. I'm just positing a reason that ikon might want to avoid pastebin. Of course, having posted on the same forum as me already is a ticket onto the 'very special super secret' watch list. Fortunately, that one is also known as the "@#$% it, we can't even find a legal justification for killing this git, so there's no way we'll be able to commit resources to tracking every contact online" list. It's basically the same as getting taken off of all the other lists.
Pharap #36
Posted 16 October 2012 - 01:06 AM
Oh, but I'm already on the "Target of opportunity" (AKA "Kill if you have plausible deniability") list, so I'm not worried about the watch lists. I'm just positing a reason that ikon might want to avoid pastebin. Of course, having posted on the same forum as me already is a ticket onto the 'very special super secret' watch list. Fortunately, that one is also known as the "@#$% it, we can't even find a legal justification for killing this git, so there's no way we'll be able to commit resources to tracking every contact online" list. It's basically the same as getting taken off of all the other lists.
Take it from a Neurotic Introvert, you sound Paranoid.
ChunLing #37
Posted 16 October 2012 - 07:56 PM
If they've already tried to kill you, you officially can't be classified as paranoid. I talked that point over with a number of mental health professionals when they were trying to have me involuntarily committed for my "idiosyncratic" belief that the government should obey the law. See, fortunately for me, they hadn't expected me to be alive to do any talking, so they delivered my body to an actual hospital. Once they realized I was alive and going to stay that way, they managed to force the ICU to release me to the psychiatric ward…but they didn't have a plan for forcing the psychiatric ward to declare me insane. I guess they presumed it wouldn't be too hard, since generally those in a psychiatric ward are presumed insane until they can definitively prove otherwise.

The fact that nobody could deny that I had indeed been subjected to unjustified use of lethal force sorta worked in my favor, I guess. Though the lethal force itself is not something I'm ready to put in my 'fun times' column. It was actually most unpleasant.
Starwaster #38
Posted 19 October 2012 - 12:22 AM
The version function doesn't work; attempts to call it result in 'attempt to call nil'

The reason is that functions can't share the same name as any variables. (i.e. you can't have a function named version because you already have a variable by that name)

(yeah I know it's not a huge bug but I thought it might be worth knowing)

Oh, and hi all. Love the mod, API looks cool too.
Well, the version variable is local, while the version function is global, so there should be no problem. Not sure why you get that error though.

Doesn't matter whether it's global or local. It's a naming restriction. Names (or identifiers in lua) are used for the same purpose in variables OR functions. Once it's declared for something, you can't then turn around and reuse the name for something else.

Renaming the variable eliminates the issue. (which, understand, it's not a huge issue; I doubt anyone out there was depending on the version function for something critical, I only posted as an FYI to the OP and to anyone else who might come across this post)
Well, it turns out that the local variable was the problem, but not for what you said. You can have all the variables you want with the same name if they are in a different scope. The problem is that the version variable is defined and assigned a values, then it's overwrited with the function, but it's still local, so os.loadAPI can't "see" the function.

Yes, ok, you can have variables with the same name in different scopes, but that's not relevant here because that's not what's happening.

Regarding the locality and its effect on the function, that doesn't happen when you don't reuse a name that you've used elsewhere. What do you think would happen if it WEREN'T local? You'd end up with a function that returns its own table entry instead of a value that had previously been assigned to that name as a variable. Same problem with different symptoms. I apologize if this comes across as argumentative because that's not my intent. Just trying to be helpful.
ChunLing #39
Posted 19 October 2012 - 02:43 AM
You can have a local identifier covering a global (or higher scope local) identifier, but if you're going to want to use that global identifier while it's covered then you're out of luck.
EatenAlive3 #40
Posted 23 October 2012 - 10:54 PM
Original post updated with example code by O.S.

Thanks for letting me use it!
Wing #41
Posted 27 October 2012 - 05:08 PM
Sketch isn't working near the end of the processe I get, "table: 35ca348a"
Matt21 #42
Posted 11 November 2012 - 01:24 AM
2534 Lines of code :unsure:/>/> OMG You are a god
Chris3606 #43
Posted 22 November 2012 - 05:25 AM
So, decided to download this api and see just how out of date it was, as far as actually being usable in 1.4.5. When I run the mine function, like so - mine("diamond",10) - from within a program, after a few blocks i end up with a line 1311: error: attempt to index ? (a nil value). Only mods installed are forge, and computercraft v1.47, minecraft 1.4.5. I presume this error has to do with the block ID list being very much out of date?

Edit: don't get it… if you look at the code, all that line is doing is serializing the map of the block which is simply assigning the block it just dug to air, and it obviously works sometimes as it seems to dig fine for at least a few blocks.
Atukaski #44
Posted 22 November 2012 - 12:59 PM
sorry for being a complete noob but how do you install it? (like where do you put this bunch of code in the computercraft.zip?)
Starwaster #45
Posted 28 November 2012 - 04:11 AM
So, decided to download this api and see just how out of date it was, as far as actually being usable in 1.4.5. When I run the mine function, like so - mine("diamond",10) - from within a program, after a few blocks i end up with a line 1311: error: attempt to index ? (a nil value). Only mods installed are forge, and computercraft v1.47, minecraft 1.4.5. I presume this error has to do with the block ID list being very much out of date?

Edit: don't get it… if you look at the code, all that line is doing is serializing the map of the block which is simply assigning the block it just dug to air, and it obviously works sometimes as it seems to dig fine for at least a few blocks.

FYI, BlockID is irrelevant since block IDs are not exposed to any CC programs. The Magic API can't really 'getBlockID'. IIRC from messing with this earlier, it can compare blocks and if it's been told it that a given block in its inventory is a particular block then it can compare that to other blocks but that's it. I don't think I tried the diamond mine function when I was trying this out, I think I just did regular mining. Maybe there's an coding error re: diamondMine() Just realized I didn't have the latest version installed so I updated and tried it out and I'm not able to repro your error. Did have some issues with the turtle turning back and forth instead of mining but that stopped after I rebooted. No errors at all though. Maybe an issue with how you installed the api? Or how you're trying to access it?


sorry for being a complete noob but how do you install it? (like where do you put this bunch of code in the computercraft.zip?)

You don't put this in the zip, you put it here: .minecraft\mods\ComputerCraft\lua\rom\apis\turtle)

(if you're running this as part of technic then it's something like .techniclauncher\technicssp\mods\ComputerCraft\lua\rom\apis\turtle
ikon106 #46
Posted 11 December 2012 - 06:35 AM
Could you post a mirror? I don't want to use pastebin :)/>/>
what's wrong with pastebin?
It doesn't work in the country I am in
matleobor #47
Posted 14 December 2012 - 01:49 AM
I cant use it! everytime I type mt.setPos with the coordinates, the turtle replies "No such program"
Justinjah91 #48
Posted 09 January 2013 - 12:51 PM
First off, I love this! I've been trying to find something like this ever since turtles came out! I do have one question: Is it possible to have a turtle upload it's exploration data to a central hub, and then redistribute that information to all of the other turtles? The reason I ask is because the exploration process takes a long time, and has to be done one turtle at a time so that they don't map each other. If this is possible, how would I go about doing it? Thanks.
Lampone #49
Posted 19 January 2013 - 12:28 PM
Just created a account to say, thx a lot. Havent used to much of the API but the mapping is just awesome!!!
Northfleet #50
Posted 22 January 2013 - 06:39 AM
This is really cool hope you make 1.4!
xInDiGo #51
Posted 22 January 2013 - 05:45 PM
from the comments i'm reading i'd assume this doesn't work in 1.4.6?

or maybe it does, &amp; i just don't quite know how to use this yet. should i do a large area of exploring? if i explore an area, and then change it, should i re explore the same area?

also, when i do a pastebin install, i install it to the root. is that a problem?

yeah i'm a total noob i can't hardly get it to do anything -.-

::edit::

well after playing around for a while i was able to install the api into the actual api folder for lua, and got around to messing with it.
  • it seems if i try to get it to explore to big of an area it'll produce an error.
  • the build didn't seem to work, kept producing an error even though i made a few blueprints
  • pathfinder wouldn't work unless the area was already explored

i admit a lot of these are probably user error but i've found a lack of support for magicturtle &amp; am just trying to see whats the dealio
NonStopGamer #52
Posted 12 February 2013 - 05:21 PM
This is really cool!!!
willhoot #53
Posted 10 June 2014 - 03:51 PM
does anyone know if this still works? or if there is another API similar to this one?
PwnagePineapple #54
Posted 12 June 2014 - 09:27 PM
I was wondering, would it be possible to have a turtle travel to fill the area of a rectangle in x and z directions, and create a hight map of the area it traveled, and send it to my OneOS computer as a sketch file using OneOS's transmit system? If so, I would like to see someone try, because I have no idea how it would work.