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

whats wrong with this code?

Started by makeme, 16 February 2013 - 08:16 AM
makeme #1
Posted 16 February 2013 - 09:16 AM
Ive been trying to create a program to create a wall with set hight and length
Spoiler

s = 2 --Slot number varible
count = {...}
function outaBlocks() -- checks if blocks are left in the full machine
if s == 16 then
if turtle.getItemCount(16) == 0 then
print("I'm outa blocks I need more")
s = 2
return false
else
end
else
end
end
function checkBlockNo() -- checks blocks left in current slot defined by s
print("checking Number of blocks left")
if turtle.getItemCount(s) == 0 then
turtle.select(s+1)
s = s + 1
else
turtle.select(s)
end
end
function checkBlock() -- checks that the block in the current slot compared with slot 16
print("Comparing blocks")
if not turtle.compareTo(16) then
turtle.select(s+1)
s = s +1
else
turtle.select(s)
end
end

function checkFuel() -- checks fuel level and refuels from slot 1 if needed (code taken from sethBling's autowood program
turtle.select(s)
  if turtle.getFuelLevel() < 20 then
	turtle.select(1)
	turtle.refuel(1)
turtle.select(s)
  end
end
function digMove() --digs a block and places the required block
checkFuel()
  checkBlockNo()
   checkBlock()
outaBlocks()
turtle.dig()
turtle.forward()
turtle.turnRight()
  turtle.turnRight()
   turtle.place()
turtle.turnRight()
turtle.turnRight()
length = length - 1
print(length)
end
function down() -- moves the turtle down
turtle.digDown()
turtle.down()
length = tonumber(count[1])
turtle.placeUp()
turtle.turnRight()
  turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
  turtle.turnRight()
   turtle.place()
turtle.turnRight()
turtle.turnRight()
depth = depth - 1
end

while true do
if table.getn(count) ~= 2 then
  print("Need 2 arguments run with autowall <lenght> <depth>")
   return false
else
  length = tonumber(count[1])
  depth =  tonumber(count[2])
  print("Total Blocks required ")
  print(length * depth)
end
if depth ~= 0 then
  if length ~= 0 then
   digMove()
  else
   down()
end
else
  return false
end
end

all it does is places blocks in a row continually and weirdly the turtle disappears but keeps building forwards

– thanks in advance
Lyqyd #2
Posted 16 February 2013 - 09:44 AM
Split into new topic.
LordIkol #3
Posted 16 February 2013 - 08:23 PM
hi makeme,

from first view i would say it is the while true loop you use.

try to change the last part of the Code like this


if table.getn(count) ~= 2 then
  print("Need 2 arguments run with autowall <lenght> <depth>")
   return false
else
  length = tonumber(count[1])
  depth =  tonumber(count[2])
  print("Total Blocks required ")
  print(length * depth)
end
while depth ~= 0 do
  if length ~= 0 then
   digMove()
  else
   down()
end
end

if you have more questions or if this does not work just let me know then i will test the code when im home :)/>

greetings Loki