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

New to coding, having trouble with placing torches

Started by TheSwiftVlogger, 27 February 2014 - 10:32 PM
TheSwiftVlogger #1
Posted 27 February 2014 - 11:32 PM
hey guys, I'm pretty new to coding and computercraft. I have already written a code that mines steps down for a number of blocks that you input as well as places torches a set number of blocks that you entered. now I am trying to write another code for a simple strip mine
this is just a function that i am writing for the code
(not tested and not the full code)

the trouble I'm having is getting the right code to turn around and place torches every 6 blocks.

Also if you see and mistakes such as misspelt words I am on my phone.

–code starts–
startScreen()
firstFuel()

for i = 1, 100 do
quickFuel()
quickInfo()

if turtle.detect() then
turtle.dig()
sleep(.5)
elseif turtle.detect() == false then
turtle.digUp()
turtle.digDown
turtle.forward()
end

if turtle.detectUp () then
turtle.digUp ()
end

if turtle.detectDown () then
turtle.digDown ()
end
—-torch placing script goes here—
end

– code ends–

if you could help that would be awesome. If you need to see the full script I'll have to wait until I'm home to past it to pastebin
Bomb Bloke #2
Posted 28 February 2014 - 01:31 AM
if i%6 == 0 then    -- Or instead of "5", however many blocks you want between torches
	turtle.turnRight()
	turtle.turnRight()
	turtle.select(16)  -- Or whatever slot hold the torches
	turtle.place()
	turtle.select(1)
	turtle.turnRight()
	turtle.turnRight()
end

i%5 gets the modulus of 5 into i, that is to say, it divides i by 5 and returns the remainder.

I'm not entirely sure if the turtle can place torches on walls in this way. You can always use "turtle.placeDown()" instead, which'd certainly be faster as the turtle wouldn't even need to turn around.

It'd be well worth looking into "while" loops. You'll need to devise a system whereby the turtle continuously detects blocks in front of / above it and digs them out until they're all gone (think of falling gravel / sand).
TheSwiftVlogger #3
Posted 28 February 2014 - 01:35 AM
if i%6 == 0 then    -- Or instead of "5", however many blocks you want between torches
	turtle.turnRight()
	turtle.turnRight()
	turtle.select(16)  -- Or whatever slot hold the torches
	turtle.place()
	turtle.select(1)
	turtle.turnRight()
	turtle.turnRight()
end

i%5 gets the modulus of 5 into i, that is to say, it divides i by 5 and returns the remainder.

I'm not entirely sure if the turtle can place torches on walls in this way. You can always use "turtle.placeDown()" instead, which'd certainly be faster as the turtle wouldn't even need to turn around.

It'd be well worth looking into "while" loops. You'll need to devise a system whereby the turtle continuously detects blocks in front of / above it and digs them out until they're all gone (think of falling gravel / sand).

thank you!
I'll add the to the code and test it if it works if it does I'll pastebin the full code for bug testing.

only been coding for 4 days lol

ill also pastebin my stairs code when I can
TheSwiftVlogger #4
Posted 28 February 2014 - 11:57 AM
hey guys here is the full code so far (still in progress) http://pastebin.com/dqnb9xZm