The function thats supposed to do all of the stuff is when numb == "F" and i left in what im currently trying to do in there. And here's all the code:
Spoiler
button = {}
input = {}
calc = ""
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
function printVerticalLine(lineX, startingY, endingY)
local curX, curY = term.getCursorPos()
term.setBackgroundColor(colors.white)
for lineY = startingY, endingY do
term.setCursorPos(lineX, lineY)
term.write(" ")
end
term.setCursorPos(curX, curY)
end
function printHorizontalLine(yLine, startingX, endingX)
local curX, curY = term.getCursorPos()
term.setBackgroundColor(colors.white)
for xLine = startingX, endingX do
term.setCursorPos(xLine, yLine)
term.write(" ")
end
term.setCursorPos(curX, curY)
end
function drawTable()
printVerticalLine(2,2,18)
--Left Border
printVerticalLine(20,2,18)
--Right Border
printVerticalLine(8,6,18)
--Left Seperator
printVerticalLine(14,6,18)
--Right Seperator
printHorizontalLine(2,2,20)
--Top
printHorizontalLine(6,2, 20)
--Upper Before Keys
printHorizontalLine(18,2,20)
--Bottom
printHorizontalLine(10,2,20)
--Upper Seperator
printHorizontalLine(14,2,20)
--Lower Seperator
term.setBackgroundColor(colors.black)
end
function drawFunctionsTable()
printHorizontalLine(6,32,50)
--Top
printHorizontalLine(10,32,50)
printHorizontalLine(14,32,50)
printHorizontalLine(18,32,50)
--Bottom
printVerticalLine(32,6,18)
--Left Border
printVerticalLine(38,6,14)
printVerticalLine(44,6,18)
printVerticalLine(50,6,18)
--Right Border
term.setBackgroundColor(colors.black)
end
function drawExtraButtonsTable()
--Help, Color settings, 2nd button for filling table with ExtraFunctions
printVerticalLine(23,6,18)
--Left Border
printVerticalLine(29,6,18)
--Right Border
printHorizontalLine(6,23,29)
--Top
printHorizontalLine(10,23,29)
printHorizontalLine(14,23,29)
printHorizontalLine(18,23,29)
--Bottom
end
function setTable(name, xmin, xmax, ymin, ymax)
button[name] = {}
button[name]["numb"] = name
button[name]["xmin"] = xmin
button[name]["xmax"] = xmax
button[name]["ymin"] = ymin
button[name]["ymax"] = ymax
end
function fillTable()
setTable("1", 3, 7, 15, 17)
setTable("2", 9, 13, 15, 17)
setTable("3", 15, 19, 15, 17)
setTable("4", 3, 7, 11, 13)
setTable("5", 9, 13, 11, 13)
setTable("6", 15, 19, 11, 13)
setTable("7", 3, 7, 7, 9)
setTable("8", 9, 13, 7, 9)
setTable("9", 15, 19, 7, 9)
end
function fillFunctionsTable()
setTable("C", 33,37,7,9)
setTable(".", 39,43,7,9)
setTable("/", 45,49,7,9)
setTable("+", 33,37,11,13)
setTable("-", 39,43,11,13)
setTable("*", 45,49,11,13)
setTable("0", 33,43,15,17)
setTable("=", 45,49,15,17)
end
function fillExtraFunctions()
setTable("^", 33,37,7,9)
setTable("rt", 39,43,7,9)
--setTable("", 45,49,7,9)
--setTable("", 33,37,11,13)
--setTable("", 39,43,11,13)
--setTable("", 45,49,11,13)
--setTable("", 33,43,15,17)
--setTable("", 45,49,15,17)
end
function fillExtraButtonsTable()
setTable("F",24,28,7,9)
setTable("H",24,28,11,13)
setTable("c",24,28,15,17)
end
function checkClick(tab, mx, my)
for i, v in pairs(tab) do
if mx >= v.xmin and mx <= v.xmax and my >= v.ymin and my <= v.ymax then
return true, v.numb
end
end
return false, nil
end
function screen()
term.setBackgroundColour(colours.black)
term.setTextColour(colours.white)
for name,data in pairs(button) do
local yspot = (data["ymin"] + data["ymax"]) / 2
local xspot = (data["xmin"] + data["xmax"]) / 2
term.setCursorPos(xspot, yspot)
write(name)
end
end
function redraw()
term.setCursorPos(4,4)
term.clearLine()
drawTable()
end
function displayHelp()
term.clear()
Help()
end
function setInput1()
input[1] = tonumber(calc)
input[2] = numb
redraw()
calc = ""
numb = ""
end
function enterPress()
input[3] = tonumber(calc)
redraw()
calc = ""
numb = ""
if input[2] == "+" then
Output = input[1] + input[3]
elseif input[2] == "-" then
Output = input1 - input[3]
elseif input[2] == "*" then
Output = input[1] * input[3]
elseif input[2] == "/" then
Output = input[1] / input[3]
elseif input[2] == "^" then
Output = input[1] ^ input[3]
elseif input[2] == "rt" then
Output = math.sqrt(input[1])
end
write(Output)
input[1] = Output
end
--[[ Running Code ]]--
drawTable()
drawFunctionsTable()
drawExtraButtonsTable()
fillTable()
fillFunctionsTable()
fillExtraButtonsTable()
screen()
while true do
local e, but, x, y = os.pullEvent("mouse_click")
if but == 1 then
bValid, numb = checkClick(button, x, y)
if bValid then
if numb == "C" then
redraw()
for i = 1,3 do
input[i] = nil
end
calc = ""
else
if numb == "+" then
setInput1()
elseif numb == "-" then
setInput1()
elseif numb == "*" then
setInput1()
elseif numb == "/" then
setInput1()
elseif numb == "^" then
setInput1()
elseif numb == "rt" then
setInput1()
elseif numb == "H" then
displayHelp()
elseif numb == "F" then
term.clear()
redraw()
drawFunctionsTable()
drawExtraButtonsTable()
fillTable()
fillExtraFunctions()
fillExtraButtonsTable()
elseif numb == "=" then
enterPress()
end
calc = calc .. numb
term.setCursorPos(4, 4)
if #calc < 14 then
write(calc)
else
write(calc:sub(#calc-14))
end
end
end
end
end