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

"Lamper!" Let a turtle make lamps for you![Version 1.1]

Started by milkywave1, 28 November 2012 - 08:44 PM
milkywave1 #1
Posted 28 November 2012 - 09:44 PM
Turtle Lamp Maker

version 1.1


This program makes lamps for you!


Why would you need that?

So you won't need to keep repeating the same style of lamp over and over again. :D/>

What's new in version 1.1:
  • New style of lamp: redstone lamp

Features so far:
  • Two Three styles of lamp to choose from!
  • A GUI to select style of lamps
​I use Wraithbone's GUI but I will code my own GUI once I get more in-depth in Lua

Some screenshots:
Opening GUI:

Glowstone lamp stuff:

Village-style lamp stuff:




Code :
Spoiler

– Lights Script by milkywave1 –
–rednet.open("right")
–Functions

local sIndex = 1
local side = 1
– This function is by Wraithbone –
function vertMenu()
local tableofItems = {"Make village-style lamps", "Make glowstone lamps", "Make redstone 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) >= 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)/2);

if i == sIndex then x = x-1 end;
term.setCursorPos(x,y);
if i == sIndex then term.write("[") end;
term.write(tableofItems);

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 vertMenu2()
print("Select direction in which the lamp will bend to :")
local tableofItems = {"Left", "Right", "Forward", "Back"}
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) >= 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)/2);

if i == side then x = x-1 end;
term.setCursorPos(x,y);
if i == side then term.write("[") end;
term.write(tableofItems);

if i == side then term.write("]") end;

y = y+1;
end

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

if s == 208 then side = side +1 end;
if s == 200 then side = side -1 end;
if side > #tableofItems then side = 1 end;
if side < 1 then side = #tableofItems end;
if s == 28 then
term.clear();
term.setCursorPos(1,1);
return tableofItems[side]
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 – Village-style lamp
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 – Glowstone Lamp
turtle.select(1)
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
if side == 2 then –Right
shiftRight()
turtle.place()
turtle.down()
turtle.select(2)
turtle.place()
turtle.down()
turtle.down()
turtle.down()
forward(2)
shiftLeft()
elseif side == 1 then –Left
shiftLeft()
turtle.place()
turtle.down()
turtle.select(2)
turtle.place()
turtle.down()
turtle.down()
turtle.down()
forward(2)
shiftRight()
elseif side == 3 then –Forward
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 side == 4 then – back
turtle.down()
turtle.placeUp()
turtle.down()
turtle.select(2)
turtle.placeUp()
turtle.down()
turtle.down()
shiftLeft()
forward(2)
shiftRight()
end
elseif sIndex == 3 then – Redstone lamp
turtle.select(1)
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.select(2)
turtle.place()
turtle.up()
turtle.select(3)
turtle.place()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
shiftRight()
forward(2)
shiftLeft()
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, torches in slot 3")
elseif sIndex == 2 then
vertMenu2()
print("Place fences in slot 1, glowstone in slot 2")
elseif sIndex == 3 then
print("Place fences in slot 1, redstone lamps in slot 2 , levers in slot 3")
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)


TODO List:
  • Code my own GUI :P/>
  • More lamp styles
  • Rednet support
Link to wraithbone's thread on GUIs and other cool stuff
milkywave1 #2
Posted 28 November 2012 - 09:47 PM
Oops. Didn't see the turtle subforums! Can a moderator or somebody move this thread? My Bad :P/>
Tiin57 #3
Posted 29 November 2012 - 12:52 AM
Oops. Didn't see the turtle subforums! Can a moderator or somebody move this thread? My Bad :P/>/>
Report the topic instead of commenting.
milkywave1 #4
Posted 29 November 2012 - 03:03 AM
Oops. Didn't see the turtle subforums! Can a moderator or somebody move this thread? My Bad :P/>/>
Report the topic instead of commenting.
Ok i'll do that
Cruor #5
Posted 29 November 2012 - 03:36 AM
Moved as requested.
Heracles421 #6
Posted 30 November 2012 - 09:43 AM
I see you need help with the GUI, want me to show you an easy way to do it? PM me if you do