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

SEN's Utilites: Advanced Code Security [TUT] [EASY]

Started by SeniorFight, 01 October 2012 - 09:47 AM
SeniorFight #1
Posted 01 October 2012 - 11:47 AM
NOTIFICATION: This is a TUTORIAL, not a response!

Welcome,

I made a simple script which allows you EASLY and fastly know 'How to make a Code on my Computer'.

It's pretty simple ("Yes for you… but me?"),
For the start, let's delete the computer name:

shell.run('clear') – shell or term denotes the screen/api/computer. 'run' is like a run program. clear is the command
term.clear()

Now, make our codes:

– first, i will precise one, we will make by a 'Function' to make a returnement!

local cmdPass = "Command" – 'local', you don't need to use it, just i like to precise local…
– "Command"… why using ""? the "" denotes text (called 'string'), and all other NUMBERS without "" are the numbers to calculate (called 'Int')
– the text in "" denotes the value (string)

local Pass = "Door"

— the cmdPass and Pass you can rename to what YOU! want

We made two passwords: "Command" (to access computer's commands) and "Door" (to open the locked door)
Now, we will make some 'protocols:'

—————————>>> ALERT! Our 'local try' won't work if there is not a return, let's make a function!

local tryMax = 3 – Max wrong passwords
local try = 0 – Wrong passwords
local pWord = "*" – pWord will be used later with read()

function ENTERPASSWORD() <—- Our function here. After wrong password, we will restart the function until closing or good password!

Now, the questions and rest of scripting:

write("Enter Password: ("..try.."/"..tryMax.."): ") – 'write', what's that?!!
– write OR print shows texts on the screen, but are different:
– write shows TEXT ONLY, and print can show "Command print(…): <Text>" on a monitor.
– I don't know exactly the difference… but it's like this!

– you remember 'pWord' ? (*), now we will use it like a char!
– read() can hide letters by a word, and this word will be pWord
– like when you enter or register a password, you can't see letters but a 'char' like * or #

local sel = read(pWord)
– os.read() or read() allows the player to CHAT with the computer, then, after pressing ENTER, the computer reads the text.

Now, time to the protocols!!!

if sel == cmdPass then – 'if' starts (a) protocol(s), must be finished by a simple 'end' (only in lua scripting)
– you can see 'sel' was used with 'local sel = read()'

shell.run('clear')
term.clear() – as you want…

–write or print…
print("Command Access Granted!") – Says to the player that he is entering the computer's command!

sleep(1.5) – Our sleep, sleep is like a wait(how many seconds?), simply enter a value of seconds

term.clear()
– Nothing, because let the player now enter his commands. End of cmdPass!
elseif sel == Pass then – elseif is if like a 'try me now if 'if sel == cmdPass' won't work!', don't need to be finished with a END, arleady 'if' needing it!

term.clear()

print("Access Granted!") – Openning the door!

sleep(1.5)

term.clear()

redstone.setOutput("left/right/back/top/bottom", true) – redstone command allows you to control redstone (the computer like a lever)
– setOutput is the command do set the lever … ( " what side? ", true or false? (on or off?))

local openTime = 5 – in seconds, how many time the door will be openned?

for i=openTime, 1, -1 do – the 'for' is like a counter, first value is FROM, next is TO, and last is STEP SIZE (enter minus to decrease, and nothing to increase)
– 'for' need an end!
term.clear() – clear the last text
write("Closing in "..i.." second(s)") – 'i' is the number what for is on
sleep(1)
end

redstone.setOutput("left/right/back/top/bottom", false) – close the door

os.shutdown() – shutdown computer

os.shutdown() and shell.run('shutdown') are differents: os.shutdown() shutdowns computer immediately, and shell.run('shutdown') runs the default shutdown command (like GoodBye… *closed*)

else – else without 'if' in end is the last possible choice in the 'if' extension
– if wrong password…

term.clear()

if try < tryMax then – if try if lower than tryMax then simply add one more until try == tryMax
try = try + 1
write('Wrong password!')
else
write('Wrong password. Closing computer…')
sleep(2)
os.shutdown()
end
sleep(1.5)
ENTERPASSWORD() – return to the beginning of 'local try' if wrong password, but we have one more wrong password!

end – end of the 'if'

end – END OF FUCTION! One command more and we're done !

ENERPASSWORD() – we must precise AFTER a function to laounch it, a function without 'laounch' can't run automatically!


THE PASTEBIN: http://pastebin.com/JaFvN9xm


Thanks for reading.
I'm french, sorry for extra big and large errors!!!
My first post on this forum.

P.S.: I'm LUA pro, YOU MUST tell me if you have a problem or question!!!

FOR MODS: i do a fatal error, please move this thread to 'Tutorials' section.
jag #2
Posted 01 October 2012 - 12:06 PM
Could you put the entire code on pastebin? So we can see it in it's finished state.
jag #3
Posted 01 October 2012 - 12:08 PM
Also, you can add some
 tags to make it easier for the eye to read!
SeniorFight #4
Posted 01 October 2012 - 12:19 PM
My brain is going do blew up, but okay.

here: http://pastebin.com/JaFvN9xm

not guaranteeing there is NO errors!