This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Furest_'s profile picture

Computer doesn't detect event a certain point...[gopher's biolock]

Started by Furest_, 19 August 2014 - 06:34 PM
Furest_ #1
Posted 19 August 2014 - 08:34 PM
Hello,
I'm actually encountering a problem with the detection of an event (biolock of gopher)

Here's the code (subtitled in english ;)/>):

--peripheriques
-- p = peripheral.wrap("back")
--lecture de la table
local handle = assert(fs.open("list", "r"), "desole, je n' ai pas pu lire la table")	 --sorry, can't read the table
local fichier = handle.readAll()
if fichier == "" then
print("table vide")					--table is empty
noms = ""
else
  noms = textutils.unserialize(fichier)
end
handle.close()
-- check si l'empreinte existe
function checkexist(info)
if noms == "" then
  print("vide")					--empty
  return false
else
  for nom, code in pairs(noms) do
   if code  == info then
	return true
   else
	return false
   end
  end
end
end
--inscrit la nouvelle carte
function newprint()
term.clear()
term.setCursorPos(1,1)
print("Veuillez entrer le nom de la personne:")			 -- enter the name of the player plz
term.setCursorPos(1,2)
nomC = read()
print("Veuillez scanner votre main svp...")			  --scan your fist plz
local event, info = os.pullEvent()
if event == "key" and info ==55 then
  os.reboot()
elseif event == "biolock" then
  if checkexist(info) == true then
   term.clear()
   term.setCursorPos(1,1)
   print("Utilisateur deja enregistre")			 --user already registered
  else
   print("Nom inconnu... Ajout a la base")			 --unknown name. added to the database
   if noms == "" then
   noms = {}
   end
   noms[nomC]  = info
   print("Nom inscrit")				 --name registered
   local output = textutils.serialize(noms)
   local handle = assert(fs.open("list", "w"), "desole, je n'ai pas pu lire la table")  --sorry, can't read the table
   handle.write(output)
   handle.close()
   print("Donnees enregistrees")			   --data registered
  end
end
end
--Attente de la lecture ou de l'étoile
while true do
print("Lecture prête")				   --ready to read
local event, info = os.pullEvent()
print("event detecte")				   --event detected
if event == "key" and info == 55 then
  print("test")
  newprint()
  sleep(2)
  os.reboot()
elseif event == "biolock" then				  --PROBLEM HAPPENS HERE!!! (cf next lines after the code)
  print("Empreinte detectee")				 --print detected
  if rs.getInput("front") == true then
   print("pas au centre")				 --you're not centered
   os.reboot()
  else
   print("empreinte lue")				 -- print read
   if checkexist(info) then
	print("ouvreporte")				 --opening door
	rs.setOutput("left", true)
	rs.setOutput("bottom", true)
	os.reboot()
   else
	print("ce joueur n'existe pas...")			 --this player doesn't exists
	sleep(5)
	os.reboot()
   end
  end
end
end

So here's the point:

According to my code, the computer needs to detect when I print my fist on the biolock.
It do when I register a new user (with the
 elseif event == "biolock" then 
)
but when I start the computer and try to detect right on, it doesn't work.
But the detection of the [*](key 55) works perfectly…

I really don't know where's the mistake…

Furest
Edited on 19 August 2014 - 06:39 PM
Bomb Bloke #2
Posted 20 August 2014 - 03:22 AM
So what happens when you touch the biolock? Does the system print "event detecte"? Does it do anything else?

Saying it "doesn't work" is less helpful than explaining what it does do.

Maybe tweak that "event detecte" line to read:

print("event detecte: "..event)

For reference, the documentation for the event comes from here:

Spoiler"biolock", print, attachName, learnedName, accessLevel

Generated when someone right-clicks the biolock and is scanned.
print is the unique hash code that represents the player on this world (or, if the config setting bioLock_GivesUsernames" is true, the true name of the player). attachName is the attachment name of the biolock, the side or lan name used to wrap the peripheral. learnedName is the name the biolock has learned to associate with this print, or "" if it has not been learned, and accessLevel is the level stored with this print, or 0 if none.
Furest_ #3
Posted 20 August 2014 - 06:04 PM
i've finally found the solution. In facts, I didn't even noticed the fistprint becaus it rebooted straight on after having scanned the correct fist :/.
I've added a delay and now it's fine!
Thanks for the support guys!