0

我在第 61 行不断收到预期的错误,但我找不到任何想法?我尝试使用计算机工艺外围设备磁卡读卡器解决并重新排列它并尝试磁卡门

os.loadAPI("SHA")
os.pullEvent = os.pullEventRaw

redstone.setBundledOutput("left",colors.white)
math.randomseed(os.time())

term.clear()
term.setCursorPos(1,1)
print("DKM.inc Doors")
print("thank you")

modem = peripheral.wrap("top")

if moden == nil then
  error("Modem not on top")
end

if moden.isPresentRemote("mag card reader_0") then
  reader = peripheral.wrap("mag card reader_0")
  print("Card reader connected")
else
  error("Mag-card reader not found")
end

if modem.isPresentRemote("monitor_0") then
  monitor = peripheral.wrap("monitor_0")
  print("monitor connected")
else
  error("monitor not found")
end

hashedPw = "0706490"
cardsFilePath = "cards"
cards = {""}
chars = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
newpass = ""
cardNum = 0

if fs.exists(cardsFilePath) then
  cardsFile = fs.open(cardsFilePath, "r")
  cards = textutils.unserialize(cardsFile.readAll())
  cardsFile.close()
end

while true do  
  admin = false
  
  monitor.clear()
  monitor.setCursorPos(1,1)
  monitor.write("Please insert card")
  reader.setInsertCardLight(true)
  
  
  event, p1,p2,p3 = os.pullEvent()
  
  if event == " mag_swipe" then
    if SHA.SHA1_2(p1) == hashePw then
      admin = true
    end
    for x = 1, #cards do
      if SHA,SHA1_2(p1) == cards[x] then --line 61 is right here
        reader.setInsertCardLight(false)
        redstone.setBundledOutput("left", 0)
        os.sleep(3)
        redstone.setBundledOutput("left", colors.white)
        reader.setInsertCardLight(true)
        break
      end
    end
  end
  if admin == true then
    reader.setInsertCardLight(false)
    monitor.clear()
    monitor.setCursorPos(1,1)
    monitor.write("Admin granted insert blank card")
    for z = 1,15 do
      case math.random(1,2)
      a = math.random(1,#chars)
      if case == 1 then
        x=string.upper(chars[a])
      elseif case == 2 then
        x=string.lower(chars[a])
      end
      newpass = newpass..x
    end
    reader.setInsertCardLight(true)
    cardNum = #cards
    print(reader.beginWrite(newpass, cardNum..""))
    table.insert(cards, SHA,SHA1_2(newpass))
  
    while reader.isWaiting() do
    end
  
    reader.setInsertCardLight(false)
    monitor.clear()
    monitor.setCursorPos(1,1)
    monitor.write("new card created")
    newpass = ""
  end

  os.sleep(1) 
 
  cardsFile = fs.open(cardsFilePath, "w")
  cardsFile.write(textutils.serialize(cards))
  cardsFile.close()

end

4

1 回答 1

1

您错过了 2 行上带有 moden 的拼写“modem”。

if moden == nil then

并且..

if moden.isPresentRemote("mag card reader_0") then

至于错误。

if SHA,SHA1_2(p1) == cards[x] then --line 61 is right here

我相信..应该是这个..

if SHA.SHA1_2(p1) == cards[x] then --line 61 is right here

交换,a.应该可以解决问题。

于 2017-01-19T22:51:15.600 回答