Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("back")
- monitor = peripheral.wrap("top")
- server = 3
- function displayBalance(balance)
- monitor.clear()
- monitor.setCursorPos(1, 2)
- monitor.write("Welcome!")
- monitor.setCursorPos(1, 4)
- monitor.write("$" .. balance)
- end
- function checkOut(balance)
- confirmation = false
- rednet.broadcast("buyrequest " .. balance)
- temp, message2 = rednet.receive(nil, 3)
- if message2 == "ping" then
- phoneid = temp
- confirmation = true
- end
- temp, message2 = rednet.receive(nil, 3)
- if message2 == "ping" then
- phoneid = temp
- confirmation = true
- end
- if confirmation then
- print("Request Sent")
- rednet.send(server, "serverbuyrequest " .. balance .. " " .. phoneid)
- id, success = rednet.receive(nil, 60)
- if success ~= "true" then
- print("Server did not return successful payment")
- rednet.send(server, "removebuyrequest " .. balance .. " " .. phoneid)
- newid, success = rednet.receive(nil, 2)
- if success ~= nil then
- print("Order " .. success .. "ly received")
- else
- print("Server did not Respond")
- end
- else
- print("SUCCESS!")
- return true
- end
- else
- print("Phone Response Failed")
- end
- return false
- end
- function evaluateFormula(formula)
- -- Load the formula as a Lua function
- local func, err = load("return " .. formula)
- -- Check if there was an error compiling the formula
- if not func then
- return nil, "Invalid formula: " .. err
- end
- -- Execute the function and return the result
- local success, result = pcall(func)
- if success then
- return result
- else
- return nil, "Error evaluating formula: " .. result
- end
- end
- balance = 0
- displayBalance(balance)
- while true do
- print("type end to confirm order \n")
- print("Current Order: $" .. balance)
- input = io.read()
- if input == "end" then
- success = checkOut(balance)
- if success then
- break
- end
- end
- if input ~= 0 and input ~= "end" then
- balance = balance + evaluateFormula(input)
- displayBalance(balance)
- end
- end
- monitor.clear()
- monitor.setCursorPos(1, 2)
- monitor.write("Thank")
- monitor.setCursorPos(1, 4)
- monitor.write("You!")
- os.sleep(5)
- displayBalance(0)
Advertisement
Add Comment
Please, Sign In to add comment