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

Little problem whit torch

Started by rum1890, 04 February 2014 - 07:52 AM
rum1890 #1
Posted 04 February 2014 - 08:52 AM
Hi to all, first sorry for my bad english, after that this is my problem :(/>

I don't know nothing of programming so is possible is a stupid error
Spoiler

a =  read()
b = a + 1
for i = 1, a, 1 do
  turtle.refuel()
  turtle.dig()
  turtle.forward()
  turtle.digDown()
  turtle.digUp()
   if b == 6 then //[u][i] this is theorical where torch start[/i][/u]
	 turtle.select(16)
	 turtle.placeDown()
	 b = 0
  end
end
turtle.turnRight()
turtle.turnRight()
for i = 1, a, 1 do
  turtle.forward()
end
for i =1,15 do
  turtle.select(i)
  turtle.drop()
end
turtle.turnRight()
turtle.turnRight()

the problem is don't place torch
anyone can help
thanks for the reply and sorry i have wrong something
have a nice day
CometWolf #2
Posted 04 February 2014 - 10:40 AM
You never increment b after defining it as a+1. This means your turtle will never place a torch, unless you input 5 as a. You'll have to add

  b = b+1
To your loop.
Edited on 04 February 2014 - 09:41 AM
LBPHacker #3
Posted 04 February 2014 - 10:44 AM
b won't get a new value unless you tell Lua explicitly to give it one. With that setup, only one torch will be placed and that's only if a equals 5. I'm sure that's not what you want (I think you want to place torches after every 6 blocks). So, forget about the b variable. Remove these lines:
b = a + 1
b = 0
Now replace the line that decides if the torch should be placed with this:
if i % 6 == 0 then
That divides i by 6 and checks if the modulo is 0.

Also, some minor tweaks:
local a = tonumber(read()) -- the local is important (unless you want to clutter the global environment; the tunumber() is not
And there's the for loop:
for i = 1, a do -- the second "1" isn't necessary

BTW: I see, CometWolf posted something before me (thank IP.Board for telling me). Well done.
Edited on 04 February 2014 - 09:45 AM
rum1890 #4
Posted 04 February 2014 - 12:22 PM
thanks to all two, tomorrow go to my friend and test (is not for me the code :D/> )

Spoilerlocal a = tonumber(read())
a = read()
b = a + 1
for i = 1, a, 1 do
turtle.refuel()
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.digUp()
if b == 6 then
if i % 6 == 0 then
turtle.select(16)
turtle.placeDown()
b = 0
end
end
turtle.turnRight()
turtle.turnRight()
for i = 1, a, 1 do
turtle.forward()
end
for i =1,15 do
turtle.select(i)
turtle.drop()
end
turtle.turnRight()
turtle.turnRight()

so green part to add and red to remove is correct this ?

thanks again
LBPHacker #5
Posted 04 February 2014 - 12:48 PM
-snip-
Yup. Oh that reminds me of GitHub.
rum1890 #6
Posted 19 February 2014 - 03:00 AM
thanks, i m go only yesterday to my friend, work, thanks again :)/>