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

Program not doing what its programmed to do:

Started by milkywave1, 27 November 2012 - 10:50 PM
milkywave1 #1
Posted 27 November 2012 - 11:50 PM
When I run my code, everything is fine. However, at the Bend towards: part, not matter what I input(back/right/forward/left) it doesn't work! Somebody please help me? I will maybe post my code when done :D/>


-- Lights Script by milkywave1 --
--rednet.open("right")
--Functions
local sIndex = 1
-- This function is by Wraithbone --
function vertMenu()
local tableofItems = {"Make village-style lamps", "Make glowstone lamps"}
local selection = "";
while (selection == "") do
  term.clear();
  local xMax, yMax = term.getSize();
  local y = math.floor(yMax/2) + math.floor(#tableofItems/2);
  y = y - #tableofItems;
  if y<1 then y = 1 end;

  if #tableofItems > yMax then
   print "ERROR: List does not fit on screen, reduce number of items in table";
   return "";
  end

  for i = 1, #tableofItems do

  if string.len(tableofItems[i]) >= xMax then
   term.clear();
   term.setCursorPos(1,1);
   print (("ERROR: List item # "..i).." is too long please reduce");
   return "";
  end
   local x = math.floor(xMax/2) - math.floor(string.len(tableofItems[i])/2);
 
   if i == sIndex then x = x-1 end;
   term.setCursorPos(x,y);
   if i == sIndex then term.write("[") end;
   term.write(tableofItems[i]);
 
   if i == sIndex then term.write("]") end;
 
   y = y+1;
  end

  local r,s = os.pullEvent("key");

  if s == 208 then sIndex = sIndex +1 end;
  if s == 200 then sIndex = sIndex -1 end;
  if sIndex > #tableofItems then sIndex = 1 end;
  if sIndex < 1 then sIndex = #tableofItems end;
  if s == 28 then
    term.clear();
    term.setCursorPos(1,1);
    return tableofItems[sIndex]
  end
end
end
function shiftLeft()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnRight()
end
function fuel()
  turtle.select(4)
  turtle.refuel()
end
function checkFuel()
  fl = turtle.getFuelLevel()
  fuel()
  if fl < 1 then
   print("Need fuel! Put coal in slot 4!")
  end
end
function forward(num)
  for i = 1,num do
  turtle.forward()
end
end
function shiftRight()
  turtle.turnRight()
  turtle.forward()
  turtle.turnLeft()
end
function makeLamp()
  if sIndex == 1 then
    turtle.select(1)
    turtle.place()
    turtle.up()
    turtle.place()
    turtle.up()
    turtle.place()
    turtle.up()
    turtle.select(2)
    turtle.place()
    turtle.back()
    turtle.select(3)
    turtle.place()
    shiftLeft()
    turtle.forward()
    turtle.place()
    turtle.up()
    turtle.forward()
    turtle.forward()
    turtle.down()
    turtle.turnRight()
    turtle.place()
    turtle.up()
    turtle.forward()
    turtle.forward()
    turtle.down()
    turtle.turnRight()
    turtle.place()
    turtle.down()
    turtle.down()
    turtle.down()
    turtle.turnRight()
    turtle.forward()
    turtle.turnRight()
  elseif sIndex == 2 then
 
    turtle.select(1)
    turtle.place()
    turtle.up()
    turtle.place()
    turtle.up()
    turtle.place()
    turtle.up()
    turtle.place()
    turtle.up()
    turtle.place()
    if ginput == "right" then
	  shiftRight()
	  turtle.place()
	  turtle.down()
	  turtle.select(2)
	  turtle.place()
	  turtle.down()
	  turtle.down()
	  turtle.down()
	  forward(2)
	  shiftLeft()
    elseif ginput == "left" then
	  shiftLeft()
	  turtle.place()
	  turtle.down()
	  turtle.select(2)
	  turtle.place()
	  turtle.down()
	  turtle.down()
	  turtle.down()
	  forward(2)
	  shiftRight()
    elseif ginput == "back" then
	  turtle.up()
	  forward(2)
	  turtle.down()
	  turtle.turnRight()
	  turtle.turnRight()
	  turtle.back()
	  turtle.place()
	  turtle.down()
	  turtle.select(2)
	  turtle.place()
	  turtle.down()
	  turtle.down()
	  turtle.down()
	  turtle.forward()
	  turtle.turnRight()
	  turtle.turnRight()
    elseif ginput == "forward" then
	  turtle.down()
	  turtle.placeUp()
	  turtle.down()
	  turtle.select(2)
	  turtle.placeUp()
	  turtle.down()
	  turtle.down()
	  shiftLeft()
	  forward(2)
	  shiftRight()
    end
  end
end
function makeLamp2()
  print("Making "..input.. " lamps")
 
  madeLamps = 0
 
  for a = 1,input do
   makeLamp()
   madeLamps = madeLamps + 1
   print("Made "..madeLamps.. " lamps")
  --rednet.send(6, madeLamps.." lamps")
  for b = 1,input2 do
   turtle.forward()
  end
end
end
function prompt()
  print("Current fuel level: "..fl)
 
  if sIndex == 1 then
    print("Place fences in slot 1, black wool in slot 2, and torches in slot 3")
  elseif sIndex == 2 then
    print("Place fences in slot 1, glowstone in slot 2")
    write("Bend towards:")
    ginput = read()
   
	    if ginput ~= "right" or ginput ~= "left" or ginput ~= "forward" or ginput ~= "back" then
	  print("Does not compute")
	  error()
    end
  
  end
  write("Number of Lamps:")
  input = read()
  write("Distance between each lamp:")
  input2 = read()
  input2 = input2 - 1
end
function reset()
  print("Returning...")
  turtle.turnLeft()
  turtle.forward()
  turtle.turnLeft()
  input2 = input2 + 1
   for z = 1,madeLamps do
	 forward(input2 + 1)
   end
  turtle.turnLeft()
  turtle.forward()
  turtle.turnLeft()
end
function main()
  vertMenu()
  checkFuel()
  prompt()
  makeLamp2()
  reset()
end
main()
turtle.select(1)
Alekso56 #2
Posted 28 November 2012 - 12:07 AM
AND not OR between the arguments:



    ginput = read()
   
         if ginput ~= "right" and ginput ~= "left" and ginput ~= "forward" and ginput ~= "back" then
          print("Does not compute")
          error()
    end
  
milkywave1 #3
Posted 28 November 2012 - 01:47 AM
Thx for the reply!

I've been trying to get the solution for hours(by hours I mean minutes):D/>. I knew that the error was on the line but couldn't find out what it was :lol:/>