What's the difference between the "while —- do" and "startup?
Well, for starters, a "while" loop runs faster then reloading the whole script back into memory over and over.
A big catch with using shell.run() to restart the script repetitively is that the previous instance of the running script does
not end when you do it. It sits there in RAM, waiting for the next instance of the script to end so it can carry on. Start enough copies of the script running, eventually you run out of RAM and the whole stack of scripts crash.
You can read up on loops
here.
What does "true" in the last example you gave me mean?
Exactly that: true.
Say you've got a line like this:
if fs.exists("status") then
When Lua runs it, it checks to see what fs.exists("status") resolves to, the answer either being true or false. Based on the result of that condition, it either runs what's in the "if" block, or it doesn't.
In some situations - such as when you want to rig a "while" loop to run forever - you might want to provide a condition that will always resolve a certain way. In those instances, you can simply refer to eg "true" directly.
true / false values are called
booleans.
How would I work that into the script?
Work out the exact bit of your script that needs to be repeated, stick "while true do" above it, a matching "end" below it, then go through and remove the shell.run() calls. You could wrap the loop around the entire script if you wanted, but if you think about it, you'll see that there are bits that only need to be run once for every time the script starts…
How to I redo the numbers you were talking about?
The code snippet I gave you does that by converting the strings it reads from the file to numbers, using the tonumber() function.
Also is this what you meant by the part where I replace the lines of code?
No. You've got two bolded sections - one is the very first line of your script, the other consists of four blocks of code. I'm saying nuke that entire second bolded section and replace it with the code I gave you.
And what is meant by: "After doing that, whenever you open the door you need to re-open the file in write mode and dump a 1 into it, and whenever you close the door you need to re-open the file and write a 0."
This is the later bit of your script where you open the door:
if input == '1' then
term.clear()
redstone.setOutput("back", true)
term.setCursorPos(2,1)
print("[Door Opened]")
sleep(1)
term.clear()
shell.run("startup")
You need to
add code in here which opens your "status" file in write mode, saves a 1 into it, then closes that file handle again.
Then take a look at the bit where you close the door, and… well, I assume you get the idea.