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

[Lua][Question] Storing data through a reboot/shutoff for a password system

Started by Kraethi, 21 January 2013 - 02:02 PM
Kraethi #1
Posted 21 January 2013 - 03:02 PM
Hello to the CC community! First post here.

I'm extremely new (~2 days ._.) to CC, and so far this forum has helped me with my first programs a lot!
However, I've recently written a program for a password lock that doesn't begin on startup (it's a "lockdown" program, so it starts whenever it's run).
The problem is, the lockdown can be overriden simply by turning the computer on and off again. So I'm trying to think of a way for the program, when it's run,
to somehow write to a file somewhere that it's locked down, and that "locked-down" status can then be erased by entering the password- but if the system reboots, something in the startup program reads the file and runs the lockdown program again. Thus, the lockdown can't be broken by rebooting.

…Sorry if that makes no sense! But I hope you all can understand what I'm trying to do.

This is what I have so far:

os.pullEvent = os.pullEventRaw
shell.run("redset", "back", "orange", "false")
print("Lockdown Override:")
password = read("*")
if password == "password" then
shell.run("redset", "back", "orange", "true")
print("Lockdown Lifted")
else
print("Override Failure")
shell.run("lockdown")
end

The startup has sets the same redstone output that this program modifies to "true".
Thanks!
-Kraethi
ChunLing #2
Posted 21 January 2013 - 03:37 PM
fs API here. io API here. I think that a lot of CC players use the fs API because it is the native method and the io is just a wrapper, but the io API is better if you're used to using it (or want to be).
Kraethi #3
Posted 28 January 2013 - 06:14 AM
Thanks! I've tried a little of the io API since the fs one seems to be lacking the operations I'm trying to use. It seems like once I figure it out it should work.
So I've written this program to look for a specific (string? sequence? character?) thing in a file.


local file = io.open("file", "r")
local state = file:read("*a")
if state == 1 then
print("found")
else print("not found")
end

The program always returns "not found" regardless of the file's actual contents.
I'm guessing the problem has something to do with the second line, but I'm not sure where to go from there.

Edit: I'm a moron and forgot the quotes around the 1. It works fine now.