Posted 24 November 2014 - 01:24 AM
I was trying to write a super simple platform building program for my turtle, and it tells me that it is "attempted to return nil" (at line 11 I think); or something like that. I'm a total programming n00b so I apologize for my cluelessness. Here is the code:
1 – Input Variabls for length and width of platform
2 local inVars = {…}
3
4
5 local width = inVars[1]
6 local length = inVars[2]
7
8 – place a block below turtle till length is reached
9 function buildForward()
10
11 for i=1, length do
12 turtle.placeDown()
13 turtle.forward()
14 end
15
16 end
17
18 – reorient turtle to the right
19 function spinRight()
20
21 turtle.right()
22 turtle.forward()
23 turtle.right()
24
25 end
26
27 – reorient turtle to the left
28 function spinLeft()
29
30 turtle.left()
31 turtle.forward()
32 trutle.left()
33
34 end
35
36 –Main program loop
37
38 for j=1, width do
39
40 buildForward()
41 spinRight()
42 j= j + 1
43
44 buildForward()
45 spinLeft()
46 j= j + 1
47 end
P.S. Why do my super simple programs choke, yet the crazy complex programs I find online work? Rhetorical question.
1 – Input Variabls for length and width of platform
2 local inVars = {…}
3
4
5 local width = inVars[1]
6 local length = inVars[2]
7
8 – place a block below turtle till length is reached
9 function buildForward()
10
11 for i=1, length do
12 turtle.placeDown()
13 turtle.forward()
14 end
15
16 end
17
18 – reorient turtle to the right
19 function spinRight()
20
21 turtle.right()
22 turtle.forward()
23 turtle.right()
24
25 end
26
27 – reorient turtle to the left
28 function spinLeft()
29
30 turtle.left()
31 turtle.forward()
32 trutle.left()
33
34 end
35
36 –Main program loop
37
38 for j=1, width do
39
40 buildForward()
41 spinRight()
42 j= j + 1
43
44 buildForward()
45 spinLeft()
46 j= j + 1
47 end
P.S. Why do my super simple programs choke, yet the crazy complex programs I find online work? Rhetorical question.