Posted 11 January 2014 - 02:11 AM
Hello, I am very new to computercraft, so please forgive
I wanted to build a recursive pyramid program that takes one parameter, and recursively calls that same program over and over again building up the walls of the pyramid til a base case.
The name of the program is pyramidmaker, and it is at the very bottom of the pastebin paste below.
After doing some print statements I am not 100% sure, but I think it has to do with my else return statement most likely because it does not make much sense to me, but not sure howto call it.
The error I am getting is..
"pyramidmaker:6: attempt to perform arithmetic __sub on nil and number"
****************************************************
–takes in side length argument
args = {…}
length = tonumber(args[1])
templength = length - 2
–print(templength .. " ")
function placeBlocks()
for i = 1, length - 1, 1 do
turtle.placeDown()
turtle.forward()
–print(i .. " ")
end
end
turtle.refuel(1)
if length == 1 then
turtle.up()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.place(1)
return 1
elseif length == 2 then
return 1
else
turtle.up()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.placeDown()
placeBlocks(length)
turtle.turnLeft()
placeBlocks(length)
turtle.turnLeft()
placeBlocks(length)
turtle.turnLeft()
–reachers original edge, stop one early
placeBlocks(length - 1)
print("before recursion call")
–probably passing an integer when it wants a string, if thats even the issue
return shell.run("pyramidmaker", templength)
end
******************************
Thank you all in advance!
Hello, thanks for approving my post.
More information if it would help is
http://pastebin.com/R03bkbvr if someone would like to run it
and I dont know if I specified, but it seems to run thru the program correctly in making the base perimeter of the pyramid, but once it calls itself again, it breaks.
Thank you all
Nevermind, you can cancel this post, I renamed it to pyro last night and forgot. It all mostly works now, just need to test more.
Admin you can delete this thread!
I wanted to build a recursive pyramid program that takes one parameter, and recursively calls that same program over and over again building up the walls of the pyramid til a base case.
The name of the program is pyramidmaker, and it is at the very bottom of the pastebin paste below.
After doing some print statements I am not 100% sure, but I think it has to do with my else return statement most likely because it does not make much sense to me, but not sure howto call it.
The error I am getting is..
"pyramidmaker:6: attempt to perform arithmetic __sub on nil and number"
****************************************************
–takes in side length argument
args = {…}
length = tonumber(args[1])
templength = length - 2
–print(templength .. " ")
function placeBlocks()
for i = 1, length - 1, 1 do
turtle.placeDown()
turtle.forward()
–print(i .. " ")
end
end
turtle.refuel(1)
if length == 1 then
turtle.up()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.place(1)
return 1
elseif length == 2 then
return 1
else
turtle.up()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.placeDown()
placeBlocks(length)
turtle.turnLeft()
placeBlocks(length)
turtle.turnLeft()
placeBlocks(length)
turtle.turnLeft()
–reachers original edge, stop one early
placeBlocks(length - 1)
print("before recursion call")
–probably passing an integer when it wants a string, if thats even the issue
return shell.run("pyramidmaker", templength)
end
******************************
Thank you all in advance!
Hello, thanks for approving my post.
More information if it would help is
http://pastebin.com/R03bkbvr if someone would like to run it
and I dont know if I specified, but it seems to run thru the program correctly in making the base perimeter of the pyramid, but once it calls itself again, it breaks.
Thank you all
Nevermind, you can cancel this post, I renamed it to pyro last night and forgot. It all mostly works now, just need to test more.
Admin you can delete this thread!