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

Help with mining script

Started by wassadam, 12 November 2013 - 11:21 AM
wassadam #1
Posted 12 November 2013 - 12:21 PM
hello. I'm new to computercraft and have tried to make my first program, and was told that there was an error and I can not even see it. please help me

Here's the code:


println("skriv lengt")
lengt = io.read()

if lengt > 0 then
turtle.up()
turtle.dig()
end

for lengtNu=1,lengt do
if 0 < turtle.getItemCount(9) then
turtle.forward()
turtle.dig()
turtle.digUp()
turtle.digDown()
end
else
turtle.turnleft()
turtle.turnleft()
for tilbage=1,(lengtNu+1) do
turtle.forward()
end
turtle.dropDown
end
end
Lyqyd #2
Posted 12 November 2013 - 05:00 PM
Split into new topic.

There's no built-in function called println. Try print instead. Use length = tonumber(read()) to convert the string read returns into a number that the for loop can use.

There are probably also logic issues that others can address.
tchoutchawn #3
Posted 13 November 2013 - 12:46 AM

...
...
01 print( "skriv lengt" )
02 length = io.read()
03 if ( length > 0 ) then
04   turtle.up()
05   turtle.dig()
06 end
07 for lengthNu = 1, length do
08   if ( 0 < turtle.getItemCount( 9 )) then
09	 turtle.forward()
10	 turtle.dig()
11	 turtle.digUp()
12	 turtle.digDown()
13   end
14 else
15   turtle.turnleft()
16   turtle.turnleft()
17   for tilbage=1,(lengtNu+1) do
18	 turtle.forward()
19   end
20   turtle.dropDown
21 end
22 end

With some indentation, I can see that you have an end that shouldn't be there at line 13.
You should also consider to use the fs api instead of the io api.

Version with fs api:


...
...
01 print( "skriv length" )
02 local file = fs.open( "filePath", "r" )
03 length = tonumber( file.readLine() )
04 if ( length > 0 ) then
05   turtle.up()
06   turtle.dig()
07 end
08 for lengthNu = 1, length do
09   if ( 0 < turtle.getItemCount( 9 )) then
10	 turtle.forward()
11	 turtle.dig()
12	 turtle.digUp()
13	 turtle.digDown()
14   else
15	 turtle.turnleft()
16	 turtle.turnleft()
17	 for tilbage = 1, (lengtNu+1) do
18	   turtle.forward()
19	 end
20	 turtle.dropDown
21   end
22 end
Lyqyd #4
Posted 13 November 2013 - 12:56 AM
Um, what? Where does the need to open a file come into play? io.read() simply does the same thing as read(), take typed input from the user.