ComputerCraft Chris Programs Code
Programs for ComputerCraft mods of Minecraft
Brought to you by:
christophedlr
--Variables declaration
--Normal configuration
length = 1;
width = 1;
space = 1;
pos = "left";
--Old configuration
oldlength = 1;
oldwidth = 1;
oldspace = 1;
oldpos = "left";
--Functions declaration
function clearScreen()
term.clear();
term.setCursorPos(1, 1);
end
--Menu of program
function menu()
clearScreen();
print("Sugar Canes Farm V1.0 - English version\n");
print("1. Start");
print("2. Configuration");
print("3. Exit\n");
write("Your choice: ");
local choice = tonumber( read() );
if choice == 1 then
start();
elseif choice == 2 then
config();
elseif choice == 3 then
print("Exiting program");
end
end
--Configuration of program
function config()
clearScreen();
print("SCF - Configuration Utility\n");
print("1. Length: "..length);
print("2. Width: "..width);
print("3. Spacing: "..space);
print("4. Position rows : "..pos);
print("5. Validate");
print("6. Cancel");
write("Your choice: ");
local choice = tonumber( read() );
if choice == 1 then
oldlength = length;
write("Length in blocks: ");
length = tonumber( read() );
config();
elseif choice == 2 then
oldwidth = width;
write("Width in blocks (2 max): ");
width = tonumber( read() );
if width > 2 then
width = 2;
end
config();
elseif choice == 3 then
oldspace = space;
write("Row spacing in blocks: ");
space = tonumber( read() );
config();
elseif choice == 4 then
oldpos = pos;
write("Position rows (left/right): ");
pos = read();
config();
elseif choice == 5 then
save();
menu();
elseif choice == 6 then
length = oldlength;
width = oldwidth;
space = oldspace;
pos = oldpos;
menu();
end
end
--Starting program
function start()
turtle.up();
for i = 1,width do
for j = 0,length do
turtle.dig();
turtle.forward();
end
if pos == "left" then
turtle.turnLeft();
elseif pos == "right" then
turtle.turnRight();
end
for x = 1,space do
turtle.forward();
end
if pos == "left" then
turtle.turnLeft();
elseif pos == "right" then
turtle.turnRight();
end
end
turtle.down();
end
--Save configuration
function save()
local file = fs.open("scf.cfg", "w");
file.writeLine(length);
file.writeLine(width);
file.writeLine(space);
file.writeLine(pos);
file.close();
end
--Load configuration
function load()
local file = fs.open("scf.cfg", "r");
length = tonumber( file.readLine() );
width = tonumber( file.readLine() );
space = tonumber( file.readLine() );
pos = file.readLine();
file.close();
oldlength = length;
oldwidth = width;
oldspace = space;
oldpos = pos;
end
--Call functions
if fs.exists("scf.cfg") then
load();
end
menu();