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

need help and a code

Started by tomsnows, 11 June 2012 - 09:19 PM
tomsnows #1
Posted 11 June 2012 - 11:19 PM
for a floppy key card to open a door this is what i have seen but i don't know how to run it or put it in the computer

[left]password = "password"[/left]

[left]debug_char = "0"[/left]

[left]term.clear()[/left]

[left]function mainLoop()[/left]
[left]while(true) do[/left]
[left]event, driveSide = os.pullEventRaw()[/left]
[left]if(even=="disk" and driveSide) then[/left]
[left]path = disk.getMountPath(driveSide)[/left]
[left]if(path) then[/left]
[left]path = path.."/access"[/left]
[left]file = fs.exists(path) and io.open(path, "r") or nil[/left]
[left]end[/left]
[left]disk.eject(driveSide)[/left]
[left]if(file and file:read()==password) then[/left]
[left]rs.setOutput("left", true)[/left]
[left]sleep(3)[/left]
[left]rs.setOutput("left", false)[/left]
[left]end[/left]
[left]if(file) then file:close() file = nil end[/left]
[left]elseif(debug_char and event=="char" and driveSide==debug_char) then return("break") end[/left]
[left]end[/left]
[left]end[/left]


[left]rs.setOutput("left", false)[/left]
[left]sfile = io.open("/startup", "w")[/left]
[left]sfile:write('shell.run("keycard")')[/left]
[left]sfile:close()[/left]


[left]repeat[/left]
[left]ok, err, val = pcall(mainLoop)[/left]
[left]if(not ok and err) then[/left]
[left]if(err=="Terminated") then print ("Access denied.")[/left]
[left]else[/left]
[left]print(err)[/left]
[left]end[/left]
[left]end[/left]
[left]until(ok and err=="break")[/left]
Bossman201 #2
Posted 12 June 2012 - 01:24 AM
First things first, there's a spelling error on line 10
if(even=="disk" and driveSide) then
if (event == "disk" and driveSide) then
So whoever you got this from probably has that error as well.

Remember to use proper code formatting. While inside a function, loop, or 'if' statement and you start a new line, press the spacebar once.

function testcode()
testcode
testcode
if testcode then
testcode
testcode
end
end
Could all of a sudden be

function testcode()
 testcode
 testcode
 if testcode then
  testcode
  testcode
 end
end
It helps find your own errors and some other cool stuff. My old computer science teacher when I was still in school wouldn't even look at unformatted code and after helping people on the forums for a short time I understand why.

And if you type (CODE) before the code and (/CODE) after the code it will look like my code. But replace the parentheses with brackets ("[", "]")

To put it on the computer,
1. Type "edit [YOURFILENAME]", type a letter, press ctrl-enter to save, then press ctrl-right arrow-enter to exit. You have just created a file.
2. Navigate to "%appdata.minecraftsaves[YOUR SAVE]computer[COMPUTER ID]" in your computer.
3. Open the file you just created with notepad, or any other text-editor (I use notepad++). Copy and paste the code into it and save the file (make sure you deleted the letter you typed earlier).
4. Now in the computer type the name of the file and it will run.

Note: Since this is for a floppy key card, you're probably going to need a Disk Drive next to the computer, and a floppy disk.
Spoilerand a door
tomsnows #3
Posted 12 June 2012 - 03:10 AM
ok thank you that helps a lot