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

Track Placer - Advanced - User Friendly

Started by HTxL, 22 March 2012 - 10:01 PM
HTxL #1
Posted 22 March 2012 - 11:01 PM
<iframe width="420" height="315" src="http://www.youtube.com/embed/ZmzA3N3_yXQ" frameborder="0" allowfullscreen></iframe>

This program has 6 main Features

The first Feature is to do place tracks
-You choose how many tracks you want to put in overall
-You can use up to 256 tracks in one use



The second Feature is to place power tracks every x normal tracks
-You can choose to place power track after a variable number of normal tracks that you choose
-You can use up to 64 power tracks in one use


The Third Feature is to put down a block as a floor in case there isnt one
-This feature will let you be calm when you are worrying about gaps in the ground which will stop the track placer (works on gaps,lava,water,air)
- If there isnt any floor to put on it the tracks , you can simply put up to 192 blocks in the track placer and it will place those blocks in the gaps on the ground or on the air



The Fourth Feature is to Break down block
-This feature will break block that are in the way of your track placer or your tracks
-The track placer will drop any block that he picked up when breaking blockes (its a must sorry)


The Fifth Feature is to come back home safely :]
-If you enable this feature , the track placer will go back all the way to the point he started at

The Sixth Feature is to place redstone torch next to every power rail place (thx dsuzyv for the idea)
-After a power rail is placed, the track placer will place a torch on the left side of the power rail to keep it on all the time
-You can use the other features with it to ensure the torch is placed 100% (unless there is bedrock)


Slot 1 - Junk which is being picked up by the Fourth Feature
Slots 2,3,4,5 - Normal tracks
Slot 6 - Power tracks
Slot 7 - Redstone torches
Slots 8,9 - Floor blocks





This mod is very helpfull at building air tracks - with the Third feature which will make the bridge for you + place down the tracks.
The code:
Spoilerfunction check©
if turtle.detect() then
if c then
turtle.dig() if turtle.getItemCount(1)>0 then
turtle.select(1) turtle.drop() end return false
else return true
end
end

end

function checkD©
if turtle.detectDown() then
if c then
turtle.digDown() if turtle.getItemCount(1)>0 then
turtle.select(1) turtle.drop() end return false
else return true
end
end

end

function checkR()

if turtle.getItemCount(7)>0 then return 7 end
return 0

end




function checkT()

if turtle.getItemCount(2)>0 then return 2 end
if turtle.getItemCount(3)>0 then return 3 end
if turtle.getItemCount(4)>0 then return 4 end
if turtle.getItemCount(5)>0 then return 5 end
return 0
end

function checkF()

if turtle.getItemCount(8)>0 then return 8 end
if turtle.getItemCount(9)>0 then return 9 end
return 0
end

function checkP()

if turtle.getItemCount(6)>0 then return 6 end

return 0

end

function putT(k)
if checkT()==0 then return true end
turtle.select(checkT())
turtle.placeDown()
sleep(0.5)
if not turtle.compareDown(checkT()) then
if k then
if checkF()==0 then return true end
turtle.digDown()
turtle.down()
turtle.select(checkF())
turtle.placeDown()
turtle.up()
turtle.select(checkT())
turtle.placeDown()

return false

else return true
end
end
end


function putP(k,f,l)
if checkP()==0 then return true end
g=true
turtle.select(checkP())
turtle.placeDown()
sleep(0.5)
if not turtle.compareDown(checkP()) then
if k then
if checkF()==0 then return true end
turtle.digDown()
turtle.down()
turtle.select(checkF())
turtle.placeDown()
turtle.up()
turtle.select(checkP())
turtle.placeDown()

else g=false

end

end
if g then
if f then
turtle.turnLeft()
check(l)
turtle.forward()
checkD(l)
turtle.select(checkR())
turtle.placeDown()
sleep(0.5)
if not turtle.compareDown(checkR()) then
if k then
turtle.digDown()
turtle.down()
turtle.select(checkF())
turtle.placeDown()
turtle.up()
turtle.select(checkR())
turtle.placeDown()
end
end
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
return false

else return true
end
end

end

term.clear()
term.setCursorPos(1,1)
write("How many tracks to put? - Sum (Slots 2,3,4,5) ")
print(newline)
Nor=read()
Nor=tonumber(Nor)
print(newline)
term.clear()
term.setCursorPos(1,1)


write("Put Powered Rail every how many tracks? (Slots 6)")
print(newline)
Pow=read()
Pow=tonumber(Pow)
print(newline)
term.clear()
term.setCursorPos(1,1)

write("Put a redstone torch next to every powered rail? (Slots 7) (yes or no)")
print(newline)
torch=read()

print(newline)
term.clear()
term.setCursorPos(1,1)


write("If there is no floor - Put one? (Slots 8,9) (yes or no) ")
print(newline)
Flo=read()
print(newline)
term.clear()
term.setCursorPos(1,1)

write("Break blocks that are in the way? (yes or no) ")
print(newline)
Brea=read()
print(newline)
term.clear()
term.setCursorPos(1,1)


write("Come back after I finish? (yes or no) ")
print(newline)
back=read()
print(newline)
term.clear()
term.setCursorPos(1,1)

a=0
b=0
if Brea=='yes' then c=true else c=false end
if back=='yes' then d=true else d=false end
if Flo=='yes' then e=true else e=false end
if torch=='yes' then f=true else f=false end
turtle.up()
turtle.forward()



while a<Nor do
sleep(1)
if checkD© then break end

if b>=Pow then
b=0
if putP(e,f,c) then break end

else
if putT(e) then break end
b=b+1

end

if check© then break end
a=a+1
turtle.forward()


end

if d then
turtle.turnLeft()
turtle.turnLeft()
while (a+1)>0 do
turtle.forward()
a=a-1
end
turtle.turnLeft()
turtle.turnLeft()
turtle.down()
end
dsuzyv #2
Posted 23 March 2012 - 07:00 AM
Excellent program! I have just a few questions/suggestions.

Firstly, if there is no floor, will there be some kinda error when it tries to place a track? I am wondering, because if you specified to not place a floor, yet it runs out of ground to place stuff on, it might be bad to have it keep dropping track into a lava pool (basically, what does it do if placeDown() isn't a valid target for the material?).

Next, I was wondering exactly how it all worked out-it looked to me like the turtle lowered itself to be sitting on the block, then deployed the track. I don't know if tracks are anything like snow, but if so, if the turtle came back on that plane, it might end up uprooting all the track it laid. Maybe. Don't know. Any case, if it were to rise one block above the track bed on the way back, it could make sure the trip is ride-able - two blocks high, at least.

Also, as I am a fan of automation, would it be possible to have the turtle turn and place a redstone torch to power the tracks? This would occupy another slot though, so perhaps it is best to leave that to the user. Meh, just an idea.

Thanks for providing your code! I don't know lua, so this works as a good crash course for letting me figure out howta build my own programs, and this uses a lot more functionality of the language than some other programs I have seen (the hack code with the ridiculous "this program is MINE!" statement, for instance).


P.S. I was wondering what the configuration of your slot settings were. More specifically, what occupied slot 1? it looked like slots 2-5 were track, 7-9 were to be flooring, so I would expect 6 to be powered track…but what is in 1? Anyways, not terribly important, but it kinda bugged me.
HTxL #3
Posted 23 March 2012 - 12:23 PM
Excellent program! I have just a few questions/suggestions.

Firstly, if there is no floor, will there be some kinda error when it tries to place a track? I am wondering, because if you specified to not place a floor, yet it runs out of ground to place stuff on, it might be bad to have it keep dropping track into a lava pool (basically, what does it do if placeDown() isn't a valid target for the material?).

Next, I was wondering exactly how it all worked out-it looked to me like the turtle lowered itself to be sitting on the block, then deployed the track. I don't know if tracks are anything like snow, but if so, if the turtle came back on that plane, it might end up uprooting all the track it laid. Maybe. Don't know. Any case, if it were to rise one block above the track bed on the way back, it could make sure the trip is ride-able - two blocks high, at least.

Also, as I am a fan of automation, would it be possible to have the turtle turn and place a redstone torch to power the tracks? This would occupy another slot though, so perhaps it is best to leave that to the user. Meh, just an idea.

Thanks for providing your code! I don't know lua, so this works as a good crash course for letting me figure out howta build my own programs, and this uses a lot more functionality of the language than some other programs I have seen (the hack code with the ridiculous "this program is MINE!" statement, for instance).


P.S. I was wondering what the configuration of your slot settings were. More specifically, what occupied slot 1? it looked like slots 2-5 were track, 7-9 were to be flooring, so I would expect 6 to be powered track…but what is in 1? Anyways, not terribly important, but it kinda bugged me.
1. When there is no floor simply as said use the third feature to auto place , if there is floor it will place automaticly if there isnt it will place one of the block you put on the (7,8,9) slots and then place on it the track. if there is lava it will do the same , place the block instead of the lava and then on it the track

2.The turtle is above the block he is laying the track on and track are considered a block just like snow , at the end the turtle just turn around and hover over all of the tracks then get to the block he started turn around and land. The way the turtle put the tracks is by putting them under him not behind him

3.yes thats a very nice idea, since there is only 1 slot for the powered rails it will be perfect to put another slot for redstone torch for it to be activated all the time
I will work on it now thanks :]

4. when you use the progrem it will tell you , slot 1 is for blocks its breaking since they are automaticly picked up to slot 1 and then the turtle drop them right after he picks them up so it wouldnt fill the first slot and then the other which are meant for the tracks and floor block.

slots 2,3,4,5, are for normal tracks
slot 6 is for power tracks
slot 7,8,9 are for floor blocks

I can maybe take a slot from the floor blocks to use it as redstone torches slot
it seems like the best idea

edit: ok done :]
dsuzyv #4
Posted 23 March 2012 - 06:12 PM
Spiffy! (Also, I may be clueless, but my name isn't. Thanks for the inclusion of the redstone torch idea though-more automation makes a lazy tunneler happy)

Thank you for clarifications and answers to my questions! It's always nice to get answers from the author on how stuff works.

So, to clarify my first question a bit. Suppose you didn't provide enough floor material, and you are going over a lava lake. If you were to run out of floor material, would it still attempt to place a track? I misread a bit, thinking that you could tell it not to place flooring, but in any case, will it still try to place track, even when it can't provide a floor?
HTxL #5
Posted 23 March 2012 - 06:46 PM
I also want to implant a feature which will let the track placer to go up and place tracks that can go up and not only 1 way
or even turning possibilty but I dont know how the user can use it efficently like "you want to turn leftright?" "how many blocks to pass before turning?" Its a little bit unhelpfull
since no one can actully use it in a way it will help them
but maybe somthing that will auto turn if it hits a wall or somthing but then again that isnt so helpfull

someone have any ideas?

Spiffy! (Also, I may be clueless, but my name isn't. Thanks for the inclusion of the redstone torch idea though-more automation makes a lazy tunneler happy)

Thank you for clarifications and answers to my questions! It's always nice to get answers from the author on how stuff works.

So, to clarify my first question a bit. Suppose you didn't provide enough floor material, and you are going over a lava lake. If you were to run out of floor material, would it still attempt to place a track? I misread a bit, thinking that you could tell it not to place flooring, but in any case, will it still try to place track, even when it can't provide a floor?

Lol I didnt notice the "Clueless" isnt the name….changed that :(/>/>

and if there isnt any floor materials the tracks will actually continue and same for enough tracks or power tracks

I've just changed the code and now if there is no floor and the put floor feature is on ,It will stop and if the return feature is on it will come back to the start
also the same case with power tracks and tracks but not with torches since its not such a big deal


wackybob #6
Posted 25 March 2012 - 03:35 AM
I like this :(/>/>

and this is sort of off topic, but what texture pack/mod are you using?
I like how the game looks :)/>/>
hamish1001 #7
Posted 25 March 2012 - 04:38 AM
cool :(/>/>
HTxL #8
Posted 25 March 2012 - 12:58 PM
I like this :(/>/>

and this is sort of off topic, but what texture pack/mod are you using?
I like how the game looks :)/>/>
The texture pack is "Faithful 32x32"

The game looks like that because im using "Sonic Ether's Unbelievable Shaders"
But you need a decent gpu for this one
immibis #9
Posted 29 March 2012 - 11:56 AM
Nice idea, and nice implementation!
Iscariah #10
Posted 19 April 2012 - 08:57 PM
Unfortunally, this doesn't work for me. It isn't the fault of the script. The part with turtle.compareDown doesn't work for me, because turtle.compareDown() itself gives me always the same 'Attempt to call nil' error. This is when I try it in the lua prompt and the same for your script. The same goes for turtle.compare(). It has a serious bug with the comparing in the version Tekkit uses I guess. Oh well, I'm faster with placing tracks than a turtle anyways. :)/>/>

EDIT: Right… I've found a backport of 1.31 for mc1.1 elsewhere on this forum. Let's try again….. I'll update this post if it works! (or not)

EDIT2: It works on the backport. Go figure… :)/>/> But still it has a bug in it I suppose… I loaded up my almost flat minecart testing world and did exactly what I did before the backport installation. (Place 100 tracks and yes to all other options) It worked fine and maybe a little too good! It never stopped until the inventory (slot 2,3,4,5) of the turtle was empty. Funny thing is that it returned to the home position like I told it too. So the script kinda works, I like it because I'm working on a SMP world which I later will use on a private Tekkit server with some of my friends and that world will contain many tracks and other stuff to begin with. I cheat all of it, but when it's on the server it's meant to play legit. Thanks for this script. It will help me with placing thousands of tracks I otherwise would have done all by myself.
Tagg #11
Posted 31 August 2012 - 04:05 AM
Hey,

First off thank you so much for taking the time to not only post but update this thread.

I am however having an issue with the code, I am getting an error saying that it is expecting a "do" on line 196 (while a sleep(1))

I don't know nearly enough about programming to know what's going on here, could you shed any light on what is going wrong?

also, in your code i am assuming that the copy-write symbols are meant to be ( c ) without the spacing of course.