Posted 06 January 2014 - 08:16 AM
Hi,
As i am beginning to learn programation, and playing tekkit lite, i though of using computercraft to get familiarized with coding in a fun environment.
I'm basically a beginner.
In order to understand the code i went step by step, i'm now having fun with locks for doors.
Here is my attempt to make my lock, using iterative instead of recursive (or vice versa? i'm declaring function instead so that i can make my own library, it's iterative no?)
local password = "0000"
local exit = "exit"
local opentime = 5
function Lockgood()
….term.clear()
….term.setCursorPos(1,1)
….write("Access Granted")
….rs.setOutput("back", true)
….sleep(opentime)
….rs.setOutput("back", false)
….end
while true do
….term.clear()
….term.setCursorPos(1,1)
….write("Password:")
….term.setCursorPos(10,1)
….local input = read("*")
….if input == password then
……..Lockgood()
……..end
….if input == exit then
……..term.clear()
……..term.setCursorPos(1,1)
……..shell.run "shell"
……..end
….else
……..term.clear()
……..term.setCursorPos(1,1)
……..write("Access denied !")
……..end
end
it tells me that i need a end to close the while loop.
I tryed many things ut as far as i know i don't need an extra end…
What did i do wrong?
Thanks in advance. :)/>
As i am beginning to learn programation, and playing tekkit lite, i though of using computercraft to get familiarized with coding in a fun environment.
I'm basically a beginner.
In order to understand the code i went step by step, i'm now having fun with locks for doors.
Here is my attempt to make my lock, using iterative instead of recursive (or vice versa? i'm declaring function instead so that i can make my own library, it's iterative no?)
Spoiler
(forget the dots, the preview don't show the indentation so i added dots. there not in the code.)local password = "0000"
local exit = "exit"
local opentime = 5
function Lockgood()
….term.clear()
….term.setCursorPos(1,1)
….write("Access Granted")
….rs.setOutput("back", true)
….sleep(opentime)
….rs.setOutput("back", false)
….end
while true do
….term.clear()
….term.setCursorPos(1,1)
….write("Password:")
….term.setCursorPos(10,1)
….local input = read("*")
….if input == password then
……..Lockgood()
……..end
….if input == exit then
……..term.clear()
……..term.setCursorPos(1,1)
……..shell.run "shell"
……..end
….else
……..term.clear()
……..term.setCursorPos(1,1)
……..write("Access denied !")
……..end
end
it tells me that i need a end to close the while loop.
I tryed many things ut as far as i know i don't need an extra end…
What did i do wrong?
Thanks in advance. :)/>