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)