Alyssa

Bank API

Oct 18th, 2014
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1. sChan = 16742
  2. foundside = 0
  3. if foundside == 0 then
  4. if peripheral.isPresent("top") and peripheral.getType("top") == "modem" then
  5. modem = peripheral.wrap("top")
  6. end
  7. end
  8. if foundside == 0 then
  9. if peripheral.isPresent("bottom") and peripheral.getType("bottom") == "modem" then
  10. modem = peripheral.wrap("bottom")
  11. end
  12. end
  13. if foundside == 0 then
  14. if peripheral.isPresent("front") and peripheral.getType("front") == "modem" then
  15. modem = peripheral.wrap("front")
  16. end
  17. end
  18. if foundside == 0 then
  19. if peripheral.isPresent("back") and peripheral.getType("back") == "modem" then
  20. modem = peripheral.wrap("back")
  21. end
  22. end
  23. if foundside == 0 then
  24. if peripheral.isPresent("left") and peripheral.getType("left") == "modem" then
  25. modem = peripheral.wrap("left")
  26. end
  27. end
  28. if foundside == 0 then
  29. if peripheral.isPresent("right") and peripheral.getType("right") == "modem" then
  30. modem = peripheral.wrap("right")
  31. end
  32. end
  33. modem.open(sChan)
  34. function getBalance(usergb)
  35.  UID = math.random(1,65535)
  36.  usergb = string.lower(usergb)
  37.  modem.transmit(sChan, UID, "Get Balance "..usergb)
  38. receivedreply = 0
  39.  while receivedreply == 0 do
  40.   event, side, fromchan, replychan, msg, distance = os.pullEvent("modem_message")
  41.   if fromchan == sChan and replychan == UID then
  42.    if oldb ~= nil then
  43.     oldb = balance
  44.    end
  45.    balance = msg
  46.    receivedreply = 1
  47.    return balance
  48.   end
  49.  end
  50.  
  51. end
Add Comment
Please, Sign In to add comment