Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local arg = {...};
- local possibleSides = {"left","right","top","bottom","back","front"};
- local data;
- local mag;
- function checkSide()
- for curSide = 1,6,1 do
- if(arg[2] == possibleSides[curSide]) then
- return true;
- end
- end
- return false;
- end
- function writeCard()
- print("Please swipe your card twice.");
- --local event, side = os.pullEvent("mag_swipe");
- mag.beginWrite(input, arg[1]);
- local event, side = os.pullEvent("mag_swipe");
- mag.cancelWrite();
- print("Writing done!");
- mag.setInsertCardLight(false);
- return true;
- end
- if(arg[1] == nil or arg[2] == nil) then
- print("Usage: writeMAG [label] [side]");
- print("Whereas [label] is the label you want to attach to the card.");
- print("[side] is the side of the Mag Reader");
- return false;
- else
- if(checkSide()) then
- if(peripheral.getType(arg[2]) == "mag card reader") then
- mag = peripheral.wrap(arg[2]);
- print("Please enter card data:");
- input = read("#");
- if not(input == nil) then
- mag.setInsertCardLight(true);
- return writeCard();
- else
- print("Error: Nothing entered.");
- end
- else
- print("That is no mag card reader!");
- end
- else
- print("ERROR: Side " .. arg[2] .. " doesn't exist!");
- return false;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement