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

[Turtle][CraftOS]Liraal's Stuff: Keycard Lock; magicTurtle API v. 1.252

Started by Liraal, 24 February 2012 - 08:21 PM
Liraal #1
Posted 24 February 2012 - 09:21 PM
Turtle-Locating API, auto builder, tunnel bore and a staircase maker too!

Does basically what the name says. Enter the starting position by magicTurtle.setPos(x, y, z) make it to face North (f=2 on F3 screen) and type magicTurtle.setNorth(). Then move it around by the use of magicTurtle.up() etc. There's a special function magicTurtle.goToPos(x,y,z,mode) which moves the turtle to the given coords. Set mode to true if you want it to break blocks that come its way, otherwise set to false.


functions:
setPos(x,y,z)
getPos()
goToPos(x,y,z)
turnLeft()
turnRight()
forward(n)
back(n)
up()
down()
tunnel(w,h,l)
staircase(w,h,l)
build(blueprint)
sketch()
mine(mode,l) --modes are diamond/regular
autoUpdate() --runs an autoupdate/remote control function in the background
setUpdateID() --sets the ID of remote control terminal
sendCommand(id, side, command) --sends remote command
road() --follow a road of redtorches
wander() --wanders aimlessly around
wanderer(func) --the above but while doing a function func
jack(sap) --plants, watches and cuts down a single tree (param is the slot with saplings)
treefarm(sap) --the same but on full auto (param as above)
landmine(slot, net) --turtle buries itself in the ground and places TNT that is triggered when someone walks on top of it. Can be armed/disarmed by rednet if net is set to true. (slot is the slot containing TNT)
patch(slot, l, w) --patches holes in the ground (slot is the slot for filling material, like dirt/gravel, l is length and w is width)
guardArea(exec, w, l) --patrols an area, if detects a hole/obstacle triggers function exec
remoteArm(id) --arms the mine of the ID given (the arming terminal must be tuned with the mine, see below setMineID())
remoteDisarm(id) -- disarms the mien
remoteSleep(id, t) -- disarms, waits 't' time and arms again
setMineID(arming, disarming) -- sets mine arming/disarming IDs (these are separate and can differ from each other)
savePos() --saves turtle pos to a file
getPosF() --gets turtle pos from file
mineGrid(slot) --makes a grid of TNT placed 1 block beneath surface
camoMine(slot) --same as above but a single TNT
digSlot(slot) --digs the given slot, if wrong material dug, drops to the ground
quarry(width,length) -- BETA quarry function
architect(width, height, length) --destroys a building to make a blueprint of it
path(facing) --experimental pathfinder to find a way when facing is clear. moves in 3d
stf(blueprint, filename) --saves a blueprint to a file filename EXPERIMENTAL
tff(filename) --returns a blueprint from file filename EXPERIMENTAL

You may use this code for your own APIs for public use for as long as you either attribute this to me or distribute unaltered. You're free to do with it whatever you want for your personal use.

Download

[attachment=84:magicTurtle1.31.txt] –newest
[attachment=67:magicTurtle1.3.txt]
[attachment=63:magicTurtle1.252.txt]
[attachment=60:magicTurtle1.251.txt] –bugged isSpace
[attachment=59:magicTurtle1.25.txt] –bug in mine() command
[attachment=54:magicTurtle1.24.txt]
[attachment=50:magicTurtleUpdate1.23.zip]
[attachment=44:magicTurtle1.22.txt]
[attachment=42:magicTurtle.txt]

TEAM:
  • Liraal (me)
  • EatenAlive3

Keycard lock

A small side-project, a keycard lock with random passwords and multi-user support. Has an admin system with control panel. Adjustable by variables within the program. Try it!

Download

[attachment=64:lock.txt] –version 1.0 (newest)
Dirkus7 #2
Posted 24 February 2012 - 11:41 PM
Thats a great idea! I will download this tomorrow and see how this works;)
Liraal #3
Posted 25 February 2012 - 02:21 PM
Updated to v1.1 of the API, new utilities are:

magicTurtle.tunnel(width, height, lenght)
magicTurtle.staircase(width, height, lenght) --cuts out a staircase in a material
magicTurtle.build(blueprint) --builds stuff
blueprint must be like:
bleuprint={layer1, layer2, etc}
layers are vertical and like so:
layer1={row1, row2, etc}
row1={block1, block2, etc}
block1, block2 are slot numbers for placed blocks or 0 for no block
Dirkus7 #4
Posted 25 February 2012 - 08:56 PM
It's a very nice API, good work! :(/>/>
ThePH #5
Posted 26 February 2012 - 01:33 AM
GG nice work. I like the build from blueprint :)/>/>
Liraal #6
Posted 26 February 2012 - 07:10 PM
Okay, new update! Now features a sketch() function to draw blueprints. Usage:

local a=magicTurtle.sketch()
magicTurtle.build(a)

I forgot. There's also a mining function:

diamondMine(length) --length is the length of the branches of the mine
Zim #7
Posted 27 February 2012 - 12:00 PM
Any way to get the absolute coords. For example I want to drop a terminal, run code, and it will summon the nearest turtle. To do that I need the terminal to be aware of its coords and the turtle to be aware of its coords - without relying on initialising the turtle/terminal with arbitary 0,0,0 coords.
Liraal #8
Posted 27 February 2012 - 01:58 PM
wait, you don't need to use arbitrary coords


magicTurtle.setPos(x,y,z)

Also, there'll be an update coming up for remote controlling over modems/rednet and detecting floppy drives automatically
Liraal #9
Posted 27 February 2012 - 03:26 PM
Update 1.23 is here! Features: automining, background enviroment handling:
if you're using autoUpdate() and turtle passes next to a disk drive with folder magicTurtleUpdate, it'll execute update file that's in said folder. Also, allows for remote control using sendCommand() function.

Also, added a list of working functions.
impatientplague #10
Posted 27 February 2012 - 06:44 PM
so ..how to i use this API , where do install it how do i run it etc..the wiki to be frank is empty almost zero doc's on this subject…that i can find
Liraal #11
Posted 27 February 2012 - 07:04 PM
save this as magicTurtle (without the '.txt' part) into your turtle's root folder (.minecraft/saves/savename/computer/computerID/).
then enter LUA prompt in-game. type 'os.loadAPI("magicTurtle")' then follow the instructions in the first post. then you can simply call the functions by using magicTurtle.functionname(params) (e.g. 'magicTurtle.tunnel(3,3,10)' )
the rest is up to you.
Marv-inside #12
Posted 27 February 2012 - 09:25 PM
Does this work with Bukkit?
Can't get it to work…
Liraal #13
Posted 27 February 2012 - 09:27 PM
well, it should, but there were weird behaviors reported connected with bukkit. Are you sure you placed it in the correct folder? Also, if you get errors, can you post them here?
panicmore #14
Posted 27 February 2012 - 09:41 PM
Thanks for telling of bout this liraal great job can I use this if I credit it to you
Liraal #15
Posted 27 February 2012 - 09:43 PM
sure, go ahead
Liraal #16
Posted 28 February 2012 - 07:26 PM
Updated to 1.24, new feature: Roads of redstone torches. place them in a row (can go up and down, but in 2-blocks-long steps) and the turtle above the first one and use magicTurtle.road()
Wired2coffee #17
Posted 29 February 2012 - 03:35 AM
I have a perfected version of the coordinate saver in my Tortoise API that will work with servers. http://pastebin.com/qURqLBp7
Liraal #18
Posted 29 February 2012 - 06:27 AM
my should handle SMP no problem, i dont see an issue. (i didnt test that, but code's code, right?)

EDIT: New version is coming along shortly. Upcoming features:
- Auto-treefarming
- Patching holes in the ground
- Patrolling an area
- Wandering around
- Saving to file
- Landmines (plain, or with fancy rednet control)
suchipi #19
Posted 29 February 2012 - 05:03 PM
save this as magicTurtle (without the '.txt' part) into your turtle's root folder (.minecraft/saves/savename/computer/computerID/).
then enter LUA prompt in-game. type 'os.loadAPI("magicTurtle")' then follow the instructions in the first post. then you can simply call the functions by using magicTurtle.functionname(params) (e.g. 'magicTurtle.tunnel(3,3,10)' )
the rest is up to you.
Alternatively put magicTurtle in .minecraft/mods/ComputerCraft/lua/rom/apis/turtle/ and it will be available to all turtles. You may need to reboot existing turtles for this to come into effect.
Liraal #20
Posted 29 February 2012 - 07:23 PM
Update 1.25 is live! New functions:


wander() –wanders aimlessly around
wanderer(func) –the above but while doing a function func
jack(sap) –plants, watches and cuts down a single tree (param is the slot with saplings)
treefarm(sap) –the same but on full auto (param as above)
landmine(slot, net) –turtle buries itself in the ground and places TNT that is triggered when someone walks on top of it. Can be armed/disarmed by rednet if net is set to true. (slot is the slot containing TNT)
patch(slot, l, w) –patches holes in the ground (slot is the slot for filling material, like dirt/gravel, l is length and w is width)
guardArea(exec, w, l) –patrols an area, if detects a hole/obstacle triggers function exec
remoteArm(id) –arms the mine of the ID given (the arming terminal must be tuned with the mine, see below setMineID())
remoteDisarm(id) – disarms the mien
remoteSleep(id, t) – disarms, waits 't' time and arms again
setMineID(arming, disarming) – sets mine's arming/disarming IDs (these are separate and can differ from each other)
savePos() –saves turtle pos to a file
getPosF() –gets turtle pos from file

If you want a specific function to be added and it's not present yet, just write it in this thread.
ScottKillen #21
Posted 29 February 2012 - 08:02 PM
The mine function calls mineDiamond(l) which is not defined, but there is an uncalled function above mine() called diamondMine(l). I am not a lua guru yet, but I think this is a bug.
Liraal #22
Posted 29 February 2012 - 08:05 PM
yes it is, ill fix it right away
thx B)/>/> my first bug in release version :unsure:/>/>

Fixed in 1.251

Added beta functions:
mineGrid()
camoMine()

These haven't been properly tested and may be bugged.
pcmaster160 #23
Posted 29 February 2012 - 11:00 PM
when I call (in lua prompt) magicTurtle.mine(diamond) it returns true and does nothing. is there something I have to define before it will mine?
ThePH #24
Posted 29 February 2012 - 11:32 PM
Where dyou get thoses ideas from? O_O
MysticT #25
Posted 01 March 2012 - 12:35 AM
when I call (in lua prompt) magicTurtle.mine(diamond) it returns true and does nothing. is there something I have to define before it will mine?
I think you have to pass a string to the function,so you should do it like this:

magicTurtle.mine("diamond")
pcmaster160 #26
Posted 01 March 2012 - 02:14 AM
when I call (in lua prompt) magicTurtle.mine(diamond) it returns true and does nothing. is there something I have to define before it will mine?
I think you have to pass a string to the function,so you should do it like this:

magicTurtle.mine("diamond")
error line 146, attempt to performace arithmetic __sub on nil and number

same error comes up on line 156 for the tunnel program with arguments 10,10,10
silverwolfx #27
Posted 01 March 2012 - 04:02 AM
when I call (in lua prompt) magicTurtle.mine(diamond) it returns true and does nothing. is there something I have to define before it will mine?
I think you have to pass a string to the function,so you should do it like this:

magicTurtle.mine("diamond")
error line 146, attempt to performace arithmetic __sub on nil and number

same error comes up on line 156 for the tunnel program with arguments 10,10,10

You probably forgot to call setPos() first. so the it's trying to do math on non-existent coords
pcmaster160 #28
Posted 01 March 2012 - 04:21 AM
when I call (in lua prompt) magicTurtle.mine(diamond) it returns true and does nothing. is there something I have to define before it will mine?
I think you have to pass a string to the function,so you should do it like this:

magicTurtle.mine("diamond")
error line 146, attempt to performace arithmetic __sub on nil and number

same error comes up on line 156 for the tunnel program with arguments 10,10,10

You probably forgot to call setPos() first. so the it's trying to do math on non-existent coords
lol we need some noob proof instructions, like call this, then this. :unsure:/>/>
Still having an issue.
now its on line 374 attempt to call nil… can someone simply write like 2 lines on how to use this api for the diamond mine
heres what i'm doing:

magicTurtle.setPos(516,13,525)
magicTurtle.mine("diamond")
Liraal #29
Posted 01 March 2012 - 06:09 AM
Seems like there was a fair amount of bugs after all. It was a simple mistake in isSpace() function, fixed in 1.252. The above should work.
BTW, remember that you can save position to file as well.
francogp #30
Posted 01 March 2012 - 09:14 AM
I cant use sendCommand with a turtle, can you post an example of ussage?
6677 #31
Posted 01 March 2012 - 09:56 AM
Reading position from file might be useful in turtle factories. Much needed feature, thanks for adding.
Liraal #32
Posted 01 March 2012 - 12:51 PM
I cant use sendCommand with a turtle, can you post an example of ussage?


-- on the turtle
magicTurtle.setPos(0,0,0)
magicTurtle.setUpdateID(11)
magicTurtle.autoUpdate()
-- on the controller
redet.open("back")
magicTurtle.sendCommand(27, "print("Hello")")

Im thinking about making a youtube video, but not for the time being.

A preview of what Im working on ATM:
-Cobble Generator
-Mining specific blocks
-Reed Farm
-Following player
-Pathfinding
-Blowing up obstacles :unsure:/>/>
Liraal #33
Posted 01 March 2012 - 09:41 PM
Added a little side-project, keycard lock with multi-user support and a built in admin panel. Try it!

It's first release so it's suspected to be full of bugs. Be sure to post them here!
pcmaster160 #34
Posted 01 March 2012 - 09:49 PM
Now i get: 'for' limit must be a number (line 385) after running this code (same as above)

magicTurtle.setPos(516,13,525)
magicTurtle.mine("diamond")

But if i use magicTurtle.mine("diamond",1) works. what does the 1 do? and how exactly does the diamond mine function work? At the moment my turtle just runs in random directions and digs at seemingly random intervals.
Liraal #35
Posted 01 March 2012 - 09:58 PM
huh. it's supposed to go to level 12 and crave a tunnel 1x2 with branches of length 'l' (yes, that's the mysterious 1 :unsure:/>/> ). I haven't properly tested it though because im playing on super-flat world and it's layer 5.
pcmaster160 #36
Posted 01 March 2012 - 10:19 PM
for me it does that then makes a X pattern in every direction from its starting point and keeps backtracking through that.

and the gotopos function is off with the z cord, it goes the opposite way it should for z and x. (if you set it to go to 10 and it is at 5, it will go to 0 instead of 10) it gets the height right though.
Liraal #37
Posted 01 March 2012 - 10:20 PM
Are you sure you used setNorth() with turtle pointing north?
pcmaster160 #38
Posted 01 March 2012 - 10:26 PM
nope. thanks! works now!
And it was being buggy in the diamond mine because I used 1 as the lenght and it kinda wanders through what it dug once it finishes the 4 paths it can go from its first square
francogp #39
Posted 01 March 2012 - 11:00 PM
I cant use sendCommand with a turtle, can you post an example of ussage?


-- on the turtle
magicTurtle.setPos(0,0,0)
magicTurtle.setUpdateID(11)
magicTurtle.autoUpdate()
-- on the controller
redet.open("back")
magicTurtle.sendCommand(27, "print("Hello")")

Im thinking about making a youtube video, but not for the time being.

A preview of what Im working on ATM:
-Cobble Generator
-Mining specific blocks
-Reed Farm
-Following player
-Pathfinding
-Blowing up obstacles :unsure:/>/>

I make it work with the print… but if I change the command to "go up", I get on the turtle "attempt to call nill" on the turtle, why?
pcmaster160 #40
Posted 02 March 2012 - 02:52 AM
can you make it so that it does not exit your application after running the goToPos command? For example in a program anything after goToPos is completed is canceled because gotopos ends the application.
Liraal #41
Posted 02 March 2012 - 06:11 AM
can you make it so that it does not exit your application after running the goToPos command? For example in a program anything after goToPos is completed is canceled because gotopos ends the application.

Okay, I'll check it.

As for up()/down() it's simple: type magicTurtle.up() instead of up() :unsure:/>/>
pcmaster160 #42
Posted 02 March 2012 - 09:45 PM
can you make it so that it does not exit your application after running the goToPos command? For example in a program anything after goToPos is completed is canceled because gotopos ends the application.

Okay, I'll check it.

As for up()/down() it's simple: type magicTurtle.up() instead of up() :unsure:/>/>
Thanks a million! I almost have a fully functional strip mining system going making 1x3 strips for me and then I can go in and collect the ores on the walls.

Also I don't know if you are aware but it seems for me at least the goToPos is slightly off sometimes. I think this is triggered by gravel (I confirm it). I had this issue initially too when tracking distance. Basically all you have to do to fix this is to check if the turtle detects anything infront of it before moving forward. Then break it before calling your forward function (which i'm guessing counts for the coords).
elminister #43
Posted 03 March 2012 - 03:55 AM
it would be nice if there someone can do a example of a little programm with that stuff.
i want to sketch and build a house from blueprint. :unsure:/>/>
Liraal #44
Posted 03 March 2012 - 07:03 AM

--Simplest blueprint builder
os.loadAPI("magicTurtle")
magicTurtle.setPos(0,0,0)
magicTurtle.setNorth()
local a = magicTurtle.sketch()
print("build? y/n")
a,b=os.pullEvent()
while a~="char" do a,b=os.pullEvent() end
if b=="y" then magicTurtle.build(a) else return "aborted" end
return true

here you go
MysticT #45
Posted 03 March 2012 - 05:36 PM

--Simplest blueprint builder
os.loadAPI("magicTurtle")
magicTurtle.setPos(0,0,0)
magicTurtle.setNorth()
local a = magicTurtle.sketch()
print("build? y/n")
a,b=os.pullEvent()
while a~="char" do a,b=os.pullEvent() end
if b=="y" then magicTurtle.build(a) else return "aborted" end
return true

here you go


--Simplest blueprint builder
os.loadAPI("magicTurtle")
magicTurtle.setPos(0,0,0)
magicTurtle.setNorth()
local a = magicTurtle.sketch()
print("build? y/n")
local evt, b = os.pullEvent()
while evt ~= "char" do evt, b = os.pullEvent() end
if b == "y" then magicTurtle.build(a) else return "aborted" end
return true
Fixed a little error :unsure:/>/>
Liraal #46
Posted 03 March 2012 - 07:03 PM
yeah right:D i have a habit of assigning 'a' variables pretty much everywhere
pcmaster160 #47
Posted 03 March 2012 - 11:57 PM
Did you see my post about the goToPos function and falling blocks? how it should check if it can move forward before it counts as moving forward when it cant.
Espen #48
Posted 04 March 2012 - 01:00 AM
@pcmaster160:
With falling sand and/or gravel it's oftentimes better to make a hindsight-check for a successful turtle movement instead of a check beforehand.
So instead of something like this…
for n = 1, 10 do
  while turtle.detect() do
	turtle.dig()
  end
  turtle.forward()
end
… you'd rather use something like this:
for n = 1, 10 do
  while not turtle.forward() do
	turtle.dig()
  end
end

The former will sometimes not move forward the whole 10 blocks depending on how the sand/gravel falls etc. because it checks blocks instead of checking its movement.
The latter is much more reliable, because the turtle will dig until all forward movements have returned true.

I mean, just think about it. You make a check for a block infront of you.
If there is a block, you dig. If sand is falling down now, then you can't detect it (while it's falling), because it's not an entity during that time.
So now you try to move forward. But between the time the sand was falling down and the time you needed to decide to move forward, it could very well happen that the sand has manifested itself as an entity again and is blocking your forward movement.
Since you're not checking the success of your forward movement (true or false), you're oblivious to the fact that you haven't actually moved yet.
If you (the turtle) had instructions to move forward 10 blocks, then you're already 1 block shy of that. :unsure:/>/>

Therefore I'd suggest to always check the return value of your movement and repeat digging until the movement returned true.
pcmaster160 #49
Posted 04 March 2012 - 05:54 AM
@pcmaster160:
With falling sand and/or gravel it's oftentimes better to make a hindsight-check for a successful turtle movement instead of a check beforehand.
So instead of something like this…
for n = 1, 10 do
  while turtle.detect() do
	turtle.dig()
  end
  turtle.forward()
end
… you'd rather use something like this:
for n = 1, 10 do
  while not turtle.forward() do
	turtle.dig()
  end
end

The former will sometimes not move forward the whole 10 blocks depending on how the sand/gravel falls etc. because it checks blocks instead of checking its movement.
The latter is much more reliable, because the turtle will dig until all forward movements have returned true.

I mean, just think about it. You make a check for a block infront of you.
If there is a block, you dig. If sand is falling down now, then you can't detect it (while it's falling), because it's not an entity during that time.
So now you try to move forward. But between the time the sand was falling down and the time you needed to decide to move forward, it could very well happen that the sand has manifested itself as an entity again and is blocking your forward movement.
Since you're not checking the success of your forward movement (true or false), you're oblivious to the fact that you haven't actually moved yet.
If you (the turtle) had instructions to move forward 10 blocks, then you're already 1 block shy of that. :unsure:/>/>

Therefore I'd suggest to always check the return value of your movement and repeat digging until the movement returned true.
exactly, thats what I did in my program but in Liraal's function to go to a position she doesnt check for it, and just wanted to give an heads up.
Liraal #50
Posted 04 March 2012 - 06:24 AM
I'm working on it, it'll be corrected in magicTurtle 1.3, as will be functions like forward and back giving return values.

BTW, I'm a he xD
Liraal #51
Posted 04 March 2012 - 12:30 PM
Okay, v. 1.3 is live! I rewrote parts of the code, goToPos should mine every obstacle before moving, forward/back now return values. Also added beta pathfinding (path() function ) and slot digging (digSlot(slot)). diamondMine will now accept additional param for slot for diamond samples (will drop everything else to the ground)
pcmaster160 #52
Posted 04 March 2012 - 05:12 PM
I'm working on it, it'll be corrected in magicTurtle 1.3, as will be functions like forward and back giving return values.

BTW, I'm a he xD
my bad :unsure:/>/>
Okay, v. 1.3 is live! I rewrote parts of the code, goToPos should mine every obstacle before moving, forward/back now return values. Also added beta pathfinding (path() function ) and slot digging (digSlot(slot)). diamondMine will now accept additional param for slot for diamond samples (will drop everything else to the ground)
Thanks! and item detection by what slot it goes in is genius, never thought of detecting items like that!
darrenbritton #53
Posted 07 March 2012 - 12:05 AM
sorry i know im a noob :unsure:/>/> but how would i go about remotly controling this , i know its something to do with the autoUpate function and setting the turtles ID,beyond that im lost B)/>/>
Gurkenmaster #54
Posted 12 March 2012 - 04:32 PM
Can you fix the up() down() forward() and down() functions?
They modify the coords even if the turtle doesn't move at all.

function up()
if y~=127 then
local state=turtle.up()
y=y + 1
return state
else return false
end
end
should be

function up()
if y~=127 then
local state=turtle.up()
if state then
y=y + 1
end
return state
else return false
end
end
Liraal #55
Posted 12 March 2012 - 06:37 PM
okay, sure, i have been getting around to do this, but i never actually did :mellow:/>/> Anyway, it'll be in the next update, along with turn-buildings-to-blueprints-by-destructive-means function.
highvoltage56 #56
Posted 13 March 2012 - 03:40 AM
For the key card lock how do I set up a control panel or add new users? Some explanation would be nice :mellow:/>/>
Liraal #57
Posted 13 March 2012 - 05:41 AM
just log in as an admin, the default user/password is on top of the code.
bobster71 #58
Posted 14 March 2012 - 10:36 AM
Thanks for making this. Saved me the trouble. Keep it coming.
Liraal #59
Posted 14 March 2012 - 09:35 PM
Okay, finally updated to v. 1.31 (of the API). New features:
- Movement functions no longer modify coords if no movement done
- Added architect(width,height,length) function. (Gets blueprint from a destroyed building.)
- Added experimental functions:

quarry(width, length)
path
(facing) experimental pathfinder to find a way when facing is clear. moves in 3d
stf(blueprint, filename) saves a blueprint to a file filename
tff
(filename) returns a blueprint from file filename

Upcoming features:
- UI
- Locating system
- Better digging with turtle.compare()
- Working blueprint management system

What more would you like to see in this API? Post your suggestions and bug reports here!
Regelneef #60
Posted 15 March 2012 - 12:36 PM
What I would really really like is an elevator function. The first time you get on, it will detect if there is nothing beneath it and it will descend (speed selectable) until it hits a block. The next time you get on it will go up and stop at the same height as you got on :D/>/>
Now I'm really an amateur with LUA, So if you could make this, I would be really happy :)/>/>
This would be brilliant to access our underwater base, gliding towards bottom in a glass lined elevator.
Espen #61
Posted 15 March 2012 - 12:51 PM
@Regelneef:
With turtles you can at least make a "descender": Stand on it and make it travel downwards. :D/>/>
Liraal #62
Posted 15 March 2012 - 12:58 PM
well, i can make a thing like this, but one catch: you'll have to jump on the way up. no way around this :D/>/>
pcmaster160 #63
Posted 16 March 2012 - 01:53 AM
Okay, finally updated to v. 1.31 (of the API). New features:
- Movement functions no longer modify coords if no movement done
- Added architect(width,height,length) function. (Gets blueprint from a destroyed building.)
- Added experimental functions:

quarry(width, length)
path
(facing) experimental pathfinder to find a way when facing is clear. moves in 3d
stf(blueprint, filename) saves a blueprint to a file filename
tff
(filename) returns a blueprint from file filename

Upcoming features:
- UI
- Locating system
- Better digging with turtle.compare()
- Working blueprint management system

What more would you like to see in this API? Post your suggestions and bug reports here!
would love a location system, but what exactly do you mean by that. Don't we kind of already have one with go to pos?
Regelneef #64
Posted 16 March 2012 - 08:38 AM
@Regelneef:
With turtles you can at least make a "descender": Stand on it and make it travel downwards. :)/>/>
Please tell me how :)/>/> I'm just to incompetent atm…

well, i can make a thing like this, but one catch: you'll have to jump on the way up. no way around this :D/>/>
But isn't it possible to use a variable (like descend or rise or derise :P/>/>) to toggle the way the elevator is going once you get on..

[pseudo code]

If player stands on turtle then check DeRise
If DeRise == 0 then
  LOOP
	 descend and DescentCounter++
  UNTIL solid block below Turtle
  DeRise = 1
END

if DeRise == 1 then
  LOOP
	 Rise and DescentCounter--
  UNTIL DescentCount == 0
  DeRise = 0
END

But I do not know yet how to program this in LUA && CC
That way you would just step on the Turtle and it will transport you back to the top

Or have I misunderstood something?
Liraal #65
Posted 16 March 2012 - 10:07 AM
a turtle physically cannot lift you. It's a block and thus cannot interact with entities that way.
Espen #66
Posted 16 March 2012 - 10:55 AM
@Regelneef:
With turtles you can at least make a "descender": Stand on it and make it travel downwards. :D/>/>
Please tell me how :)/>/> I'm just to incompetent atm…
It works literally how I said:
  1. Stand on a turtle
  2. Make it go downwards by repeatedly calling turtle.down()
There's really not much more to it. At least regarding the basic functionality.
Regelneef #67
Posted 16 March 2012 - 02:43 PM
a turtle physically cannot lift you. It's a block and thus cannot interact with entities that way.

THNX for the information, its back to the drawingboard for me :D/>/>


It works literally how I said:
  1. Stand on a turtle
  2. Make it go downwards by repeatedly calling turtle.down()
There's really not much more to it. At least regarding the basic functionality.

THNX :)/>/>
DoctorCube #68
Posted 17 March 2012 - 03:50 AM
Looks like in the newest release the back function is the same as forward.

Also on a fresh machine I need to turn it once before I can move the machine.
Not really sure why this is. I assume it might have something to do with facing I'm not sure.

EDIT I managed to sortof fix the second issue by adding

local state=false

to the head of the script. Not so sure this is helping now.
Liraal #69
Posted 17 March 2012 - 06:50 AM
Okay, the back() issue was really stupid one :D/>/> Fixed both. Await it in the next release later today.
KrahkaMaster #70
Posted 18 March 2012 - 01:28 PM
Of Topic Question: Can Mining/Wireless Turtles do both? I mean, can there be a Wireless Mining Turtle?
Liraal #71
Posted 18 March 2012 - 01:31 PM
yes, combine a turtle, a pick and a modem

on-topic: release should be done by today's evening (UTC+01:00). no promises though
Liraal #72
Posted 18 March 2012 - 02:28 PM
Okay, I decided to release an early beta version to let someone else bug-test is for me :D/>/> On Friday i reached a milestone of 1,2k lines of code and decided to implement a totally new design. Download now include a folder with modules for the API. Usage almost the same, the only differences are that you need to place magicTurtleLoader file and mT folder in root directory AND run the API via magicTurtleLoader. Loading info is toggle-able by config option (magicTurtleConfig within the mT folder). All commands still work as usual and are called by magicTurtle. prefix (e.g. magicTurtle.getPos()). There is an unfinished GUI present and accessible by UIrun() function. All changes to API variables (like rednet IDs) are now saved to config file as well. Features to be done for full version of 1.4 include: working feedback system, config options for switching the modules on and off, working GUI and a path resolver. Expect all sorts of weird error and bugs as this is really early beta.

Current modules include:
magicTurtleCore –coords and goToPos. the only obligatory module
magicTurtleMine
magicTurtleMove
magicTurtleBuild
magicTurtleWeapon
magicTurtleGUI
magicTurtleRemote
magicTurtleUtils
magicTurtleTerm –module for the terminals, not loaded on turtles

Download:
[attachment=96:magicTurtle1.4.zip]
Extract to the root folder.
MrPanda1593 #73
Posted 18 March 2012 - 10:55 PM
Hey I'm kind of a noob but the quarry function is not working properly for me. i get an error like "magicTurtle:156: attempt to perform arithmetic __add on nil and number" so what do I do to fix this?Also how do I run the v1.4 beta? Like the title above my non-pic I'm pretty clueless .
Liraal #74
Posted 19 March 2012 - 05:42 AM
you have to use setPos function earlier, otherwise it'll keep throwing up errors, I think i will fix it in the next release.

as for beta 1.4, extract to turtle's root and run magicTurtleLoader
Muud12 #75
Posted 19 March 2012 - 06:27 PM
How install this?
Liraal #76
Posted 19 March 2012 - 09:35 PM
find your turtle's root (.minecraf/saves/savename/computer/turtleID/) and extract the zip contents there.

I fixed the functions not working properly when coords weren't set, and now i have one question:

Do you want me to make a possibility of getting turtle coords even when using plain CC functions like turtle.forward?
Lupee #77
Posted 20 March 2012 - 10:38 PM
hey all love the api, I created a builder that works a little differently then magic turtles blueprint, it takes a text file as an input
in the form:
4
4
4
0_00
0__0
0__0
0000


0_00
0__0
0__0
0000


0000
0__0
0__0
0000

0000
0000
0000
0000
(where the first three lines are width,length,height, yeah I know i could of worked them out programatically if i weren't so lazy) and places them down in that format, it comes down to the ground when its out of blocks, resumes when you fill it up, and destroys any blocks that are in the way,if your interested in the source/Idea Liraal or anyone else for that matter let me know, I'd rather someone picked it up, made it better and put it in an awesome api then to just give it to people as is. : )
Gotthard #78
Posted 22 March 2012 - 02:27 AM
Any instructions on how to load this onto a SMP server's computer? I tried putting it into the computer's folder, and the loader *says* it works, but absolutely nothing registers. I'm not sure what the 'root folder' is, I tried every folder on both the client and the server, and the only thing that sort of works is either in the API folder, or the computer's folder. Yet no matter the variation on magicTurtle.tunnel() I try (all variations of camelCase, parenthesis, parameters, etc.) the 'no program found' error always arises. I must be doing something stupid here, any advice on how to load this? Looks to be some pretty amazing functions.
Luanub #79
Posted 22 March 2012 - 03:31 AM
Try using os.loadAPI("file path") and see if it will load. You can also run apis from the prompt and see if list it in the loaded api's.

You should be placing the API in the server folders and not the clients
Liraal #80
Posted 22 March 2012 - 06:21 AM
1) Have you tried it SSP as well? I didn't have time for SMP testing so something may have gone wrong.
2) Computer's root = computer's main directory (the local one), not server's ROM. (ROM version will probably be included in the next release). It could work if you place BOTH loader and mT folder inside rom/programs/
3) Are you sure you are using Lua prompt for launching the functions? They're not programs.
4) If the loader says it's working, I can see no reason why it shouldn't.
5) Why I use loader is that I divided the code and some APIs must be loaded first. Try

os.loadAPI("mT/magicTurtle")
os.loadAPI("mTmagicTurtleCore")
os.loadAPI("mT/magicTurtleMine)

or just wait for the full 1.4 release in a couple of days. :(/>/>

EDIT: A brief overview of upcoming features for next release:
- Blueprint management
- Feedback over rednet
- Turtle keeps position even when using turtle.forward() etc. Added turtle movement events called when the turtle moves.
- Blowing up obstacles / spamming over rednet
- ROM version
Gotthard #81
Posted 23 March 2012 - 12:35 AM
Well, nothing at all works on the client side, but I can get it to work server side if I manually copy the files into the computer's root. I can't get any of the mods to load manually using any of the commands. Super annoying, because I have to go back out and coy it into the new computer's root everytime I re-place the robot.

Also, it bugs out after tunnel, and spins in place. Of course, my non-standard usage of it might not be helping.
Liraal #82
Posted 23 March 2012 - 06:02 AM
I think that is a bug with goToPos. Expect a fixed release later today. Also with ROM version.

EDIT: Checked that, a stupid mistake with variables.

Edit2: Version beta 2, fixed a couple of bugs, new module: magicTurtlePlugin (turtle API overwriting), added new functions as follow:
sendFeedback() –sends feedback over rednet [Remote module]
getFeedback() [Remote/Term module]
randomDig() –digs at random [Mine module]
getSlotActive() –returns the currently selected slot [Plugin module]

Also, turtle now updates its coordinates even when using 'turtle.' functions, as long as magicTurtlePlugin is installed.
Gotthard #83
Posted 23 March 2012 - 11:11 PM
Well it appears to all be loading correctly (and automatically, when I put it into the api folder!) but anytime I run the 'tunnel' command from the lua promt the turtle locks up.

Command I run is 'magicTurtle.tunnel(3,3,3). I know the tunnel code is pretty much fine, I used it and made kmy own program so I could try to debug this while my turtles worked.

I feel like I have to be missing something obvious if it works so well for most people. I put it in the /mods/computercraft/lua/rom/apis folder. Didn't change anything.

[edit] actually it appears to lock up now under any command or program, and I had to delete the loaderRom to continue using my turtles.
Liraal #84
Posted 23 March 2012 - 11:19 PM
what do you mean by lock up?
and sorry, but i forgot to mention that loaderRom goes to rom/programs/ not rom/apis.
Gotthard #85
Posted 23 March 2012 - 11:46 PM
The lua prompt will never come back… like it's in an infinite loop or something.

When I put it into programs, it says 'can't find magicTurtleAPI' … the loaderRom is in the programs file, and the mt directory is nested in the programs directory.

In rom, it loaded but didn't work right. I think the regular programs would maybe lock up because you overrode their functions, and since your functions froze up….

[edit] ok the loader is in programs, but the MT directory goes in the API?
hamish1001 #86
Posted 24 March 2012 - 12:04 AM
cool
Liraal #87
Posted 24 March 2012 - 05:35 AM
you got it right:
loader goes to rom/programs
mT folder to rom/apis
try it and tell me whether it will lock again. I myself am unable to reproduce this.

——————————————————————————————————-

A brief tutorial about how to add your module to the API (it's simple, really)

Supposing you have a function:

function turn360()
for i=1,4,1 do turnLeft() end
end

And you want to add it to a module to use in the API later on. You need to first add a bit of code to wrap the basic commands.

local env = getfenv()
for k,v in pairs( magicTurtleCore ) do
env[k] = v
end
setfenv(<Module name>,env)
where <Module name> is the name of your module. Then you write the normal code and on the end you have to add the functions to the API itself, this way:

if not magicTurtle then print("Requires magicTurtle to run") end
rawset(magicTurtle,"turn360",turn360)
and do not mistake the string "turn360" with the function of the same name, because it won't work then.

Okay, I hope I got it through. If you've got any questions, just ask me.

EDIT: EatenAlive3 joined the team and we're in for some big changes!
EatenAlive3 #88
Posted 30 March 2012 - 06:03 PM
Big changes indeed. Welcome to a new era of turtles, coming soon to a turtle near you.
Mlmiii #89
Posted 02 April 2012 - 12:07 AM
How do you use this API's tunnel program instead of the default API's tunnel program?
EatenAlive3 #90
Posted 02 April 2012 - 10:50 PM
In this API are functions, rather than programs. To call the tunnel function, just type magicturtle.tunnel(1,2,3) from either within the Lua console, or within edit in your own programs.
Mlmiii #91
Posted 04 April 2012 - 02:26 AM
I tried that, but it says "trying to access ? a nil value".
EatenAlive3 #92
Posted 04 April 2012 - 02:40 AM
Instead of 'magicturtle', use the file name that you saved the API as. I have it as mt, I think that by default it is 'magicTurtle'.
kinxkinxkin #93
Posted 08 April 2012 - 12:24 PM
I have try magicTurtle and get many problem,
1. I let the turtle setPos(111,222,333) and savePos() but when I restart the game and let the turtle getPosF() and check the pos by getPos()
it didn't read the number it save before and show it's 0,0,0,0

function getPosF()
local f1=io.open("pos/posx", "r")
local f2=io.open("pos/posy", "r")
local f3=io.open("pos/posz", "r")
local f4=io.open("pos/face", "r")
x=f1:read()
y=f2:read()
z=f3:read()
face=f4:read()
f1:close()
f2:close()
f3:close()
f4:close()
end

this is the script I find out in the api, can anyone help me?

Sorry for my poor english


I use mT 1.4 beta 2.zip
M1cr0man #94
Posted 08 April 2012 - 03:01 PM
Would you be able to add a function to make 'moulds' of blueprints? I want to make a huge building using IC2 CF-Sprayer but i need a mould to contain the foam.
EatenAlive3 #95
Posted 08 April 2012 - 04:21 PM
@kinxkinxkin, 1.4 is currently in beta, so bugs are expected. If you want a stable release, continue to use 1.3 until 1.4 is fully released.

@M1cr0man: If you mean making hollow versions of blueprints, that is certainly possible. I can add that in. Otherwise, I don't understand what you mean.
kinxkinxkin #96
Posted 08 April 2012 - 05:19 PM
@kinxkinxkin, 1.4 is currently in beta, so bugs are expected. If you want a stable release, continue to use 1.3 until 1.4 is fully released.

@M1cr0man: If you mean making hollow versions of blueprints, that is certainly possible. I can add that in. Otherwise, I don't understand what you mean.

but i use 1.3 is also can't use the getPosF() function, it also can't load the pos
EatenAlive3 #97
Posted 08 April 2012 - 07:35 PM
Try something like this, and tell me what happens. I've never had any difficulty with saving and loading the position.

setPos(60,64,60,2)
savePos()
getPosF()
M1cr0man #98
Posted 08 April 2012 - 11:43 PM
@M1cr0man: If you mean making hollow versions of blueprints, that is certainly possible. I can add that in. Otherwise, I don't understand what you mean.
Yeah, thats exactly what i mean :P/>/> It would be great if you could add it.
drdoom30 #99
Posted 27 May 2012 - 07:05 PM
How do I install this?
EatenAlive3 #100
Posted 27 May 2012 - 11:13 PM
save this as magicTurtle (without the '.txt' part) into your turtle's root folder (.minecraft/saves/savename/computer/computerID/).
then enter LUA prompt in-game. type 'os.loadAPI("magicTurtle")' then follow the instructions in the first post. then you can simply call the functions by using magicTurtle.functionname(params) (e.g. 'magicTurtle.tunnel(3,3,10)' )
the rest is up to you.
reptar #101
Posted 30 June 2012 - 07:23 PM
alright this probably sounds very nooby, but how do i get rid of the .txt on the end of the file?
reptar #102
Posted 01 July 2012 - 06:37 PM
I think a faceNorth function could be really useful in this API
Aquilamo #103
Posted 15 July 2012 - 01:57 PM
I don't think the landmine api is working: it gives "magicTurtle1.31:147: attempt to perform arithmetic __sub on nil and number" when
I write "landmine(1, true)" in the lua command line. Am I doing something wrong?
MysticT #104
Posted 15 July 2012 - 08:45 PM
I don't think the landmine api is working: it gives "magicTurtle1.31:147: attempt to perform arithmetic __sub on nil and number" when
I write "landmine(1, true)" in the lua command line. Am I doing something wrong?
I think you have to set the turtle position first. If you don't, it tries to move and change it's position, but it's not set, so it throws the error.
Use setpos(x, y, z) before and it should work.
Aquilamo #105
Posted 16 July 2012 - 01:41 AM
Ahahaha, thank you, I'm a real noob at using what other people make.
25hz #106
Posted 15 October 2013 - 09:01 PM
So, this thread is pretty old, but hopefully the API is still valid. All the links to the text files and the archived ZIP are non-working. Is this project essentially dead now?