SHOW:
|
|
- or go back to the newest paste.
| 1 | os.pullEvent = os.pullEventRaw | |
| 2 | checkoutcomputer = 32 | |
| 3 | alogin = "adminpassword" | |
| 4 | ||
| 5 | function connect() | |
| 6 | rednet.open("bottom")
| |
| 7 | end | |
| 8 | ||
| 9 | success = pcall(connect) | |
| 10 | if not success then | |
| 11 | os.reboot() | |
| 12 | end | |
| 13 | ||
| 14 | monitor = peripheral.wrap("top")
| |
| 15 | if not monitor then | |
| 16 | os.reboot() | |
| 17 | end | |
| 18 | ||
| 19 | function displayBalance(balance) | |
| 20 | monitor.clear() | |
| 21 | monitor.setCursorPos(1, 2) | |
| 22 | monitor.write("Welcome!")
| |
| 23 | monitor.setCursorPos(1, 4) | |
| 24 | monitor.write("$" .. balance)
| |
| 25 | end | |
| 26 | ||
| 27 | function checkOut(balance) | |
| 28 | success = false | |
| 29 | while success ~= "true" do | |
| 30 | rednet.send(checkoutcomputer, balance) | |
| 31 | id, success = rednet.receive() | |
| 32 | end | |
| 33 | print("SUCCESS!")
| |
| 34 | end | |
| 35 | ||
| 36 | function evaluateFormula(formula) | |
| 37 | -- Load the formula as a Lua function | |
| 38 | local func, err = load("return " .. formula)
| |
| 39 | ||
| 40 | -- Check if there was an error compiling the formula | |
| 41 | if not func then | |
| 42 | return nil, "Invalid formula: " .. err | |
| 43 | end | |
| 44 | ||
| 45 | -- Execute the function and return the result | |
| 46 | local success, result = pcall(func) | |
| 47 | if success then | |
| 48 | return result | |
| 49 | else | |
| 50 | return nil, "Error evaluating formula: " .. result | |
| 51 | end | |
| 52 | end | |
| 53 | ||
| 54 | balance = 0 | |
| 55 | displayBalance(balance) | |
| 56 | ||
| 57 | while true do | |
| 58 | print("type end to confirm order \n")
| |
| 59 | print("Current Order: $" .. balance)
| |
| 60 | input = io.read() | |
| 61 | if input == alogin then | |
| 62 | os.exit(1) | |
| 63 | end | |
| 64 | if input == "end" then | |
| 65 | checkOut(balance) | |
| 66 | break | |
| 67 | end | |
| 68 | if input ~= 0 then | |
| 69 | change = evaluateFormula(input) | |
| 70 | if change then | |
| 71 | balance = balance + change | |
| 72 | end | |
| 73 | displayBalance(balance) | |
| 74 | end | |
| 75 | end | |
| 76 | monitor.clear() | |
| 77 | monitor.setCursorPos(1, 2) | |
| 78 | monitor.write("Thank")
| |
| 79 | monitor.setCursorPos(1, 4) | |
| 80 | monitor.write("You!")
| |
| 81 | os.sleep(5) | |
| 82 | displayBalance(0) | |
| 83 | ||
| 84 |