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

Platform Maker

Started by Acuena, 07 June 2013 - 02:21 PM
Acuena #1
Posted 07 June 2013 - 04:21 PM
I have made a platform program that does what the name implies.
Thougt I could share it with thoose that want it.

Update (13-08-04): Changed it's moving pattern. It now don't move outside the area you specify, as if you say 5x5, it will move 5x5.

Update (13-06-25): Added to it should return to the start when done.

Changelog:
Spoiler1.2
Changed the moving pattern so it dosent move outside the area you give it.
1.1
Added a function that moves the turtle back when it is done
Added a function that handles moving backwards.
1.0:
Initial release

Expand the spoiler if you want to read what it checks before and while it runs.
Spoiler
  • It checks if something is in the way and keeps trying to move forward until it can, and then resumes making the platform.
  • It checks it's current fuel level and if needed, it refuels from slot 1. If there is no fuel in slot 1 it will wait until fuel is placed in slot 1.
  • It checks if there is any builiding block in the selected slot, and if not it selects the next slot and moves on.
  • It counts how many blocks the user has provided it with and checks if it is enughe to build the platform, if not it aborts and informing the player.
  • It checks if the size of the platform requiers more than 960 block and aborts if it does. This is bacause it can't hold more than 960 blocks (15 slots)
  • Returns to the block it started

How to use:
  1. Place fuel in slot 1
  2. Fill the rest of the slots with the block you want to use, you don't have to fill them all
  3. Use the command: platform <length> <width>
  4. Watch it go
When it's done, it will tell you how many blocks it placed and how many times it had to refuel.
Pastbin link (Version 1.2): http://pastebin.com/2fMcYvGQ
For thoose that want and can use pastebin to input the code into a mining turtle, use this command: pastebin get 2fMcYvGQ platform
Older versions:
SpoilerPlatform maker 1.0: http://pastebin.com/Bt9u65cg
Platform maker 1.1: http://pastebin.com/s6VEHF9h

And here is the code if you can't download the code with the above method:
Spoiler– * Platform maker 1.2
– * Made by: Acuena
– * Usage: platform length width

– Variables
curslot = 2
fuelused = 0
blocksplaced = -1
totalnrblocks = 0

– Functions

function moveforward()
while not turtle.forward() do
checkfuel()
end
end

function moveback()
while not turtle.back() do
checkfuel()
end
end

function checkfuel()
if turtle.getFuelLevel() < 1 then
turtle.select(1)
if not turtle.refuel(1) then
print("No fuel in slot 1, awaiting fuel")
while not turtle.refuel(1) do
end
print("Successfully refueld, continuing")
end
fuelused = fuelused + 1
turtle.select(curslot)
end
end

function turnright()
turtle.turnRight()
moveforward()
turtle.turnRight()
end

function turnleft()
turtle.turnLeft()
moveforward()
turtle.turnLeft()
end

function checkblockcount()
if turtle.getItemCount(curslot) == 0 then
selnextslot()
end
end

function selnextslot()
curslot = curslot + 1
if curslot > 16 then
print("Out of blocks, terminating")
error()
end
turtle.select(curslot)
end

function place()
checkblockcount()
turtle.placeDown()
blocksplaced = blocksplaced + 1
end

function countblocks()
for i = 2,16 do
turtle.select(i)
totalnrblocks = totalnrblocks + turtle.getItemCount(i)
end
if not totalnrblocks == 0 then
totalnrblocks = totalnrblocks + 1
end
turtle.select(curslot)
end

function returntostart()
if orient == true then
turtle.turnRight()
for i = 1, width - 1 do
moveforward()
end
turtle.turnRight()
moveback()
elseif orient == false then
turtle.turnLeft()
for i = 1, width - 1 do
moveforward()
end
turtle.turnRight()
for i = 1, length do
turtle.back()
end
end
end

– Code

local args = {…}
orient=false
if #args ~= 2 then
print("Usage: platform length width")
return
end

length = tonumber(args[1])
width = tonumber(args[2])

countblocks()
need = length * width

if need > 960 then
print("Unable to carry more than 960 block's")
print("A platform with the size of:")
print(length.."x"..width.." will need "..need.." blocks")
print("Aborting run")
error()
end

if totalnrblocks < need then
print("Not enough blocks, aborting")
print("Need: "..need)
print("Have: "..totalnrblocks.." block's")
error()
end

moveforward()
place()
for xx = 1,width - 1 do
for x = 1, length-1 do
moveforward()
place()
end

if orient == false then – Should turn right
turnright()
place()
else – Should turn left
turnleft()
place()
end
orient = not orient
end
for x = 1, length-1 do
moveforward()
place()
end
print("Orient: "..tostring(orient))
returntostart()
print("Platform done")
print("Block's placed: "..blocksplaced)
print("Fuel used: "..fuelused)
IntrovertedSiko #2
Posted 22 June 2013 - 09:07 PM
Great program :)/>
Can't imagine it breaking. Just a side-note, you might want to make it go back to the start when it's done, just so it's not hanging over the edge
Niseg #3
Posted 23 June 2013 - 09:49 AM
you might want to make it go back to the start when it's done, just so it's not hanging over the edge

This looks like a classic implementation of platform building (very common) . The problem with this implementation is that the ending position is never the start position . It's still easy to predict where it is : if the "width " is an odd number it ends up in the opposite corner and if the "width" Is an even number it ends up in the "next corner". This is a forward building script with so the next corner is always counterclockwise in the case of an odd "width"
IntrovertedSiko #4
Posted 24 June 2013 - 04:34 PM
I'm not sure if I'm understanding you correctly but, couldn't you record dummy coordinates? Like starting position is 0,0 and when it goes forward one, it's 1,0 and so forth. And when it's done it just keeps moving back and subtracting until it get's back to 0,0
Acuena #5
Posted 24 June 2013 - 07:50 PM
Updated the program, se the first post.

Took a different approch than Niseg suggested.
Since I have a variable that keeps track of which way the turtle should turn, I used that one to determine how it should return to the start posistion.
Let me know if it buggs out, it have not while testing it.
Acuena #6
Posted 04 August 2013 - 01:48 PM
Updated the program. It now wont go outside the area you give it.
zanskrila #7
Posted 06 September 2013 - 09:40 AM
Hey i've used this for planting saplings, which works great, but it's losing saplings somehow. It will only plant about half of them and lose the other half.
lordphoenixmh #8
Posted 06 September 2013 - 01:19 PM
Hey i've used this for planting saplings, which works great, but it's losing saplings somehow. It will only plant about half of them and lose the other half.
Now that's a cool idea. I wouldn't have thought to use a platform program for planting saplings.
Acuena #9
Posted 13 September 2013 - 04:50 PM
Hey i've used this for planting saplings, which works great, but it's losing saplings somehow. It will only plant about half of them and lose the other half.

Hmm strange, tested it with Oak Saplings and it worked evry time. I used the command: platform 8 8 to plant 64 saplings and it planted them all evry time. I had two extra in the turtle.
civilwargeeky #10
Posted 16 September 2013 - 10:41 PM
Cool Program. If you want to challenge yourself, you should remove the limitation that it can only carry an inventory's worth of materials. You could have, say, a chest behind it at start, and when it runs out of materials it will come back to the start to get more.
Acuena #11
Posted 17 September 2013 - 02:40 PM
Cool Program. If you want to challenge yourself, you should remove the limitation that it can only carry an inventory's worth of materials. You could have, say, a chest behind it at start, and when it runs out of materials it will come back to the start to get more.

An easier way would be having a enderchest. Could just place it infron of itself and suck a full inventory full and then brake it again.
Hmm I might implement that someday :P/>