View difference between Paste ID: xwu73mnL and 9vmjyPVt
SHOW: | | - or go back to the newest paste.
1
hasMon = false;
2
list = {}
3
i = 1;
4
len = 0;
5
if peripheral.isPresent("top") then
6
	hasMon = true;
7
	mon = peripheral.wrap("top");
8
	print("Monitor was found!");
9
	mon.clear();
10
	mon.setCursorPos(1,1);
11
end
12
13
function nl()
14
	if hasMon == true then
15
	local x,y = mon.getCursorPos();
16
	mon.setCursorPos(1, y+1);
17
	end
18
end
19
20
function printm(str)
21
	if type(str) ~= "string" then return end
22
	print(str);
23
	mon.write(str);
24
	nl();
25
end
26
27
function drawScreen()
28
	if hasMon == true then
29
		mon.clear();
30
		for j = 1,len do
31
			printm(list[j]);
32
		end
33
	end
34
end
35
36
function add()
37
	print("Enter your task: ");
38
	listAns = read();
39
	if type(listAns) == "string" then
40
		list[i] = i .. " - " .. listAns;
41
		printm(list[i]);
42
		print(i .. " - " .. list[i]);
43
		i = i +1;
44
		len = len +1;
45
	end
46
end
47
48
function removeFromList(n)
49
	table.remove(list, n);
50
end
51
52
function remove()
53
	print("Which task would you like to remove?");
54
	removeAns = read();
55
	if type(removeAns) == "string" then
56
		removeAns = tonumber(removeAns);
57
		if removeAns <= len then
58
			removeFromList(removeAns);
59
		end 
60
	end
61-
	draw();
61+
	drawScreen();
62
end
63
64
function start()
65
	while true do
66
		print("What would you like to do?");
67
		print(" - Type \"add\" to add an item");
68
		print(" - Type \"remove\" to add an item");
69
		print(" - Type \"quit\" to save and quit");
70
		ans = read();
71
		if type(ans) == "string" then
72
			if ans == "add" then add() end
73
			if ans == "remove" then remove() end
74
			if ans == "quit" then 
75
				printm("Goodbye!");
76
				os.shutdown();
77
			end
78
		end
79
	end
80
end
81
82
start();