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

Keycard Errors

Started by jacobc436, 23 July 2012 - 11:21 PM
jacobc436 #1
Posted 24 July 2012 - 01:21 AM
I'm using someone else's code, it's for a keycard access door. Here's a video link of how it should work.
[media]http://www.youtube.com/watch?v=0AtCnk-YU_A&feature=related[/media]
Here's the code.
http://www.everfall....hp?rkgwiqeu1k8k
Whenever I run it, it won't let me stop it suing the normal Ctrl+T, how do i stop this program?
cant_delete_account #2
Posted 24 July 2012 - 02:05 AM
You don't. Unless you delete:

if(err=="Terminated") then print("Access denied.")
from the code.
jacobc436 #3
Posted 24 July 2012 - 02:16 AM
It gives me an error,
bios:206: [string "code-working":51: 'until' expected (to close 'repeat' at line 46)

the code was changed in the following way:


repeat
	ok, err, val = pcall(mainLoop)
	if(not ok and err) then
		else print(err) end
		rs.setBundledOutput(bundleSide, 0)
	end
until(ok and err=="break")
there are actually 8 spaces inbetween the start of the line and else print(err) end and rs.setBundledOutput(bundleSide, 0)
Noodle #4
Posted 24 July 2012 - 04:02 AM
Most of the code in this vid is just for him, everything is put in the right place. Another thing, Make your own! Its simple.. just read the apis.
API'S
You only need the fs api and the event's (read tutorials).
jacobc436 #5
Posted 24 July 2012 - 04:11 AM
Most of the code in this vid is just for him, everything is put in the right place. Another thing, Make your own! Its simple.. just read the apis.
API'S
You only need the fs api and the event's (read tutorials).

…yes but I don't know how to code Lua, only how to read and edit certain parts… TO TUTORIAL..ville
Noodle #6
Posted 24 July 2012 - 08:29 AM
Lol I'll help
This is made for the program called startup.

side = "" -- Replace with the diskreader side
rsside = "" -- Replace with the door side
print("Insert Keycard")
while true do
  sleep(0)
  if disk.isPresent(side) then
	if fs.exists("disk/pass") then
	  hFile = fs.open("disk/pass", "r")
	  if hFile.readAll() == "Blah" then
		hFile.close()
		print("Access Granted")
		rs.setOutput(rsside, "true")
		sleep(5)
		rs.setOutput(rsside, "false")
	  end
	else
	  print("Access Denied")
	  disk.eject(side)
	  shell.run("startup")
	 end
  end
end
Darky_Alan #7
Posted 24 July 2012 - 08:43 AM
I DON'T WANT TO LOOK AT THIS THREAD CAUSE IT MAKES ME FEEL UNNORIGINAL, I HAD THIS EXACT SAME IDEA LAST NIGHT AND I'VE BEEN WORKING ON IT ALL FUCKING DAY. I WANT TO FEEL UNIQUE SO I'M MAKING THIS POST TO MARK IT AS I'VE REPLIED IN HERE AND IGNORE IT AS MUCH AS POSSIBLE. I STILL WANT TO WRITE MY OWN CODE AND FEEL PROUD ABOUT IT.
Noodle #8
Posted 24 July 2012 - 08:52 AM
^ LMAO.
Really? This was done in CC v1.0
Darky_Alan #9
Posted 24 July 2012 - 08:54 AM
^ LMAO.
Really? This was done in CC v1.0
I'm new to computercraft and coding in general.

Clicky.
Noodle #10
Posted 24 July 2012 - 09:03 AM
Saw your post. Nice.
Darky_Alan #11
Posted 24 July 2012 - 09:06 AM
Saw your post. Nice.

Bottom line is I still want to go through the trouble of doing this myself.

Rather than Copy/pasting someone else's code and just say I did it.
Noodle #12
Posted 24 July 2012 - 09:07 AM
Well, it helps to look at other people's code to do so.. I joined in CC 1.1 so I'm a bit experienced.
Darky_Alan #13
Posted 24 July 2012 - 09:20 AM
Well, it helps to look at other people's code to do so.. I joined in CC 1.1 so I'm a bit experienced.

I know it does, hence why earlier in a thread I asked for a list of disk API's, I found one myself so I should be good, I don't feel like coding tonight and I'm on my laptop. Can't test out my code on this even if I use the emulator, since I'd be missing the disk drive and an actual floppy. (My laptop can't run MC much less Tekkit for shit)

I also have a pretty close friend who'se awesome at programming giving me tips and tricks, he doesn't really know lua perse but he knows a bunch of other languages and has guided me through syntax, variables, functions, etc..
Noodle #14
Posted 24 July 2012 - 09:22 AM
Experiment using args ?? It seems not as realistic but it works 0.0
Darky_Alan #15
Posted 24 July 2012 - 09:30 AM
Experiment using args ?? It seems not as realistic but it works 0.0

Args short for "Arguments"?

I'd have to use arguments one way or another, considering I have to tell the program in which direction the disk drive is.
Noodle #16
Posted 24 July 2012 - 09:32 AM
^ Args = Arguments
You don't have to, just make a var with the direction or put "bottom", "left", etc.
jacobc436 #17
Posted 24 July 2012 - 03:39 PM
Lol I'll help
This is made for the program called startup.

side = "" -- Replace with the diskreader side
rsside = "" -- Replace with the door side
print("Insert Keycard")
while true do
  sleep(0)
  if disk.isPresent(side) then
	if fs.exists("disk/pass") then
	  hFile = fs.open("disk/pass", "r")
	  if hFile.readAll() == "Blah" then
		hFile.close()
		print("Access Granted")
		rs.setOutput(rsside, "true")
		sleep(5)
		rs.setOutput(rsside, "false")
	  end
	else
	  print("Access Denied")
	  disk.eject(side)
	  shell.run("startup")
	 end
  end
end

It looks like that waits for a Keycard, if the keycard has a file named "Blah" it'll eject and turn on a redstone output sleep(5) and turn off the redstone output… But I have a bundle of cables that output to two noteblocks and a door, one that notifies the door is open, another that notifies the door closed or an improper keycard was entered.
Darky_Alan #18
Posted 26 July 2012 - 12:12 PM
Spoiler
Lol I'll help
This is made for the program called startup.

side = "" -- Replace with the diskreader side
rsside = "" -- Replace with the door side
print("Insert Keycard")
while true do
  sleep(0)
  if disk.isPresent(side) then
	if fs.exists("disk/pass") then
	  hFile = fs.open("disk/pass", "r")
	  if hFile.readAll() == "Blah" then
		hFile.close()
		print("Access Granted")
		rs.setOutput(rsside, "true")
		sleep(5)
		rs.setOutput(rsside, "false")
	  end
	else
	  print("Access Denied")
	  disk.eject(side)
	  shell.run("startup")
	 end
  end
end

It looks like that waits for a Keycard, if the keycard has a file named "Blah" it'll eject and turn on a redstone output sleep(5) and turn off the redstone output… But I have a bundle of cables that output to two noteblocks and a door, one that notifies the door is open, another that notifies the door closed or an improper keycard was entered.


What color output are you using for open, and what color are you using for denied?
Pinkishu #19
Posted 26 July 2012 - 12:43 PM
You should use events instead of while+sleep
Noodle #20
Posted 26 July 2012 - 04:05 PM
Updated with events
side = "" -- Replace with the diskreader side
rsside = "" -- Replace with the door side
print("Insert Keycard")
while true do
  event, p1 = os.pullEvent("disk")
  if p1 == side then
	if fs.exists("disk/pass") then
	  hFile = fs.open("disk/pass", "r")
	  if hFile.readAll() == "Blah" then
		hFile.close()
		print("Access Granted")
		rs.setOutput(rsside, "true")
		sleep(5)
		rs.setOutput(rsside, "false")
	  end
	else
	  print("Access Denied")
	  disk.eject(side)
	  shell.run("startup")
	end
end
end