Posted 05 February 2013 - 03:52 PM
This is realy getting annoying.
I want the screen to touch out of two places to select a choice when verifying the transaction and the screen will not complete the action on either.
This code is still in developement so no saying I am ripping people off.
here is my code.
I want the screen to touch out of two places to select a choice when verifying the transaction and the screen will not complete the action on either.
This code is still in developement so no saying I am ripping people off.
here is my code.
local function printGUI()
monitor.setCursorPos(1,1)
monitor.write("_____________ _____________ _____________ ______ _______ ")
monitor.setCursorPos(1,2)
monitor.write(":Add Chicken: :Add Beef : :Add Pork : :DONE: :CLEAR: ")
monitor.setCursorPos(1,3)
monitor.write("_____________ _____________ _____________ ______ ______")
monitor.setCursorPos(1,4)
monitor.write("______________________________ ")
monitor.setCursorPos(1,5)
monitor.write("Chicken: "..cNum)
monitor.setCursorPos(1,6)
monitor.write("Beef: "..bNum)
monitor.setCursorPos(1,7)
monitor.write("Pork: "..pNum)
monitor.setCursorPos(1,8)
monitor.write("Total Price: "..tdue.."$")
monitor.setCursorPos(1,9)
monitor.write("Press DONE when finished.")
end
local function getBal()
handle = fs.open("disk/creditCard", "r")
aNum = tonumber(handle.readAll())
bal = math.sqrt(aNum)
return bal
end
local function subBal(tdue)
getBal()
handle = fs.open("disk/creditCard", "w")
handle.write(" ")
newbal = (bal - tdue) * (bal - tdue)
handle.write(newbal)
handle.close()
end
local function clearScreen()
monitor.clear()
printGUI()
end
local function printTitle()
monitor.clear()
monitor.setCursorPos(1,5)
monitor.write("Press Screen to continue....")
sleep(1)
end
monitor = peripheral.wrap("right")
mside = "right"
screen = 0
cNum = 0
bNum = 0
pNum = 0
tdue = 0
while true do
printTitle()
local event, p1 = os.pullEvent()
if event == "monitor_touch" then
screen = 1
repeat
clearScreen()
local event, side, x, y = os.pullEvent("monitor_touch")
if x >= 1 and x <= 13 then
if y == 1 or y == 2 or y == 3 then
cNum = cNum + 1
tdue = tdue + 5
end
elseif x >= 16 and x <= 29 then
if y == 1 or y == 2 or y == 3 then
bNum = bNum + 1
tdue = tdue + 5
end
elseif x >= 31 and x <= 44 then
if y == 1 or y == 2 or y == 3 then
pNum = pNum + 1
tdue = tdue + 5
end
elseif x >= 46 and x <= 51 then
if y == 1 or y == 2 or y == 3 then
monitor.setCursorPos(1,10)
monitor.write("Please enter card now. Touch screen to continue")
event, side = os.pullEvent()
if event == "monitor_touch" then
monitor.clear()
monitor.setCursorPos(1,5)
getBal()
if bal >= tdue then
monitor.write("Your balance is "..bal)
monitor.setCursorPos(1,6)
monitor.write("The amount due is "..tdue)
monitor.setCursorPos(1,7)
monitor.write("Do you wish to pay it?")
monitor.setCursorPos(1,1)
monitor.write(" _____ ____")
monitor.setCursorPos(1,2)
monitor.write(" : YES NO")
local event, side, x, y = os.pullEvent("monitor.touch") -- I cannot get the darn thing to procceed with the selection here.
if x >= 3 and x <= 5 then
if y == 1 or y == 2 or y == 3 then
monitor.setCursorPos(1,8)
monitor.write("Completing Transaction")
subBal(tdue)
end
elseif x == 12 or x == 13 then
if y == 1 or y ==2 or y == 3 then
monitor.setCursorPos(1,8)
monitor.write("Canceling Transaction")
end
end
sleep(1)
screen = 0
pNum = 0
bNum = 0
cNum = 0
tdue = 0
end
elseif x >= 53 and x <= 60 then
if y == 1 or y == 2 or y == 3 then
cNum = 0
bNum = 0
pNum = 0
tdue = 0
end
end
end
end
until screen == 0
end
end