Advertisement
LokeYourLord

Untitled

Jun 8th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. local arg = {...};
  2. local possibleSides = {"left","right","top","bottom","back","front"};
  3. local data;
  4. local mag;
  5.  
  6. function checkSide()
  7. for curSide = 1,6,1 do
  8. if(arg[2] == possibleSides[curSide]) then
  9. return true;
  10. end
  11. end
  12. return false;
  13. end
  14.  
  15. function writeCard()
  16. print("Please swipe your card twice.");
  17. --local event, side = os.pullEvent("mag_swipe");
  18. mag.beginWrite(input, arg[1]);
  19. local event, side = os.pullEvent("mag_swipe");
  20. mag.cancelWrite();
  21. print("Writing done!");
  22. mag.setInsertCardLight(false);
  23. return true;
  24. end
  25.  
  26. if(arg[1] == nil or arg[2] == nil) then
  27. print("Usage: writeMAG [label] [side]");
  28. print("Whereas [label] is the label you want to attach to the card.");
  29. print("[side] is the side of the Mag Reader");
  30. return false;
  31. else
  32. if(checkSide()) then
  33. if(peripheral.getType(arg[2]) == "mag card reader") then
  34. mag = peripheral.wrap(arg[2]);
  35. print("Please enter card data:");
  36. input = read("#");
  37. if not(input == nil) then
  38. mag.setInsertCardLight(true);
  39. return writeCard();
  40. else
  41. print("Error: Nothing entered.");
  42. end
  43. else
  44. print("That is no mag card reader!");
  45. end
  46. else
  47. print("ERROR: Side " .. arg[2] .. " doesn't exist!");
  48. return false;
  49. end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement