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

Password always incorrect?

Started by Dwrlesky, 12 April 2013 - 12:49 AM
Dwrlesky #1
Posted 12 April 2013 - 02:49 AM
Im not very familar with lua, but i made a small code for a password protected door (actually, i copied the code from a tutoral and added pcall() to prevent strg+T
However, everytime i enter the password, it is incorrect.

correctpass = "test"
write("enter Password:")
pass = pcall(read)
if pass == (correctpass) then
write("Correct, you may enter")
redstone.setOutput("bottom", true)
pcall(sleep,4)
os.shutdown()
else
write("Incorrect")
pcall(sleep,2)
os.shutdown()
end

And when i try to put up os.pullEvent = os.pullEventRaw, it just writes a java error.
Anyone who can help me?
theoriginalbit #2
Posted 12 April 2013 - 02:54 AM
the reason is that pcall returns the success of the function call followed by the value returned by the function call, so you need to do this

local ok, pass = pcall(read)
Dwrlesky #3
Posted 12 April 2013 - 03:02 AM
It works, thank you :)/>
but what means the lokal ok, i mean, why i have to write it?

Ok, now i want to send a redstone signal from one pc (with modem) to another, but i am absolutely clueless how to do it.
Edited on 12 April 2013 - 01:16 AM
theoriginalbit #4
Posted 12 April 2013 - 03:20 AM
the local means that the variable cannot be accessed from outside of your program or the function it is contained in.
as for the ok, as I explained the function pcall returns 2+ values, whether the function worked or not, and the value(s) that function returns.

EDIT:
You can read more on the local keyword here: http://www.lua.org/pil/4.2.html
You can read more on pcall here: http://www.lua.org/pil/8.4.html and by googling "Lua:pcall"

As for sending RedNet messages from one computer to another, take a look in the "tutorials" section for the "Using Network Cables" topic, or look up the Rednet API on the wiki if you are using an older version of CC and cant use the awesome new features.
Edited on 12 April 2013 - 01:27 AM
Dwrlesky #5
Posted 12 April 2013 - 03:34 AM
ok, thank you again, i take a look