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

Needs Formating. Help?

Started by GuiltySpark96, 18 August 2012 - 12:03 PM
GuiltySpark96 #1
Posted 18 August 2012 - 02:03 PM
I'm quite new to the scripting scene so it would be greatly appreciated if someone could help me with mistake checking, I know I haven't formatted this at all so it would be nice if someone could tell me when you put the spaces and such and also if someone could tell me how I could add a password to debug?

The code is here:

Vault Lock

function os.pullEvent()
local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
if event == "terminate" then
end
return event, p1, p2, p3, p4, p5
end

term.clear()
term.setCursorPos(1,1)
print "Vault Security System v1"
print " "
write ("Insert Password To Continue: ")

correctpass = "password"
pass = read("*")

if pass == (correctpass) then
print " "
write("Password Accepted. Opening…")
redstone.setOutput ("back" true)
sleep (3)
redstone.setOutput ("back" false)
os.reboot()
else
print " "
write("Password Incorrect. Laser System Active…")
redstone.setOutput ("bottom" true)
sleep(1)
redstone.setOutput ("bottom" true)
os.reboot()
end
sjele #2
Posted 18 August 2012 - 02:25 PM

function os.pullEvent()
  local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
  if event == "terminate" then
  end
  return event, p1, p2, p3, p4, p5
end								 --Are the lines above this to prevent termination?
									--If so you could just change it to os.pullEvent = os.pullEventRaw

term.clear()
term.setCursorPos(1,1)
print ("Vault Security System v1")
print(" ")
write ("Insert Password To Continue: ")

correctpass = "password"
pass = read("*")

if pass == correctpass then
  print(" ")
  write("Password Accepted. Opening...")
  redstone.setOutput ("back" true)
  sleep (3)
  redstone.setOutput ("back" false)
  os.reboot()
else
  print(" ")
  print("Password Incorrect. Laser System Active...")
  redstone.setOutput ("bottom" true)
  sleep(1)
  redstone.setOutput ("bottom" true)
  os.reboot()
end

Allso when you do use == to compare use it like this

if a == b then
  --code
end
If you don't have a var to compare too use:
if a == "password" then
  -code
end

Print is used like this:
To print text do:

print("Text is here")
To print a variable do:

text = Hello
print(text)

You used print like this.

print "Text to print"

Allso how i format: On each statement thats needs an end i do it like this: (helps me find were to put ends)


if blah == something then
  --code
  --More code
elseif blah == someotherStuff then
  --code
else
  --code
end
When i make functions:
function blah()
  print("blah blah")
  print("more random stuff to print")
end
GuiltySpark96 #3
Posted 18 August 2012 - 02:40 PM
Thanks for taking the time to do this, helps out alot. :(/>/>
May I also ask how to copy this onto a floppy disk?

EDIT: Getting an error: bios:206: [string "startup"] :1: '=' expected?
sjele #4
Posted 18 August 2012 - 02:50 PM
fs.copy name disk/nameOnDisk
Exsample – Hmm how do i spell that? English is my second language :(/>/>

fs.copy("myFile", "disk/myFile2") --You can only do it like this in a file or in lua() command place
This would copy the file myFile, too disk and name the file myFile2 on the disk.
I belive you can do it like this from terminal:
copy myFile disk/myFile2