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

Edit file from Lua?

Started by Laketri, 03 August 2013 - 08:10 AM
Laketri #1
Posted 03 August 2013 - 10:10 AM
Title: Edit file from Lua?

I've written a login system, and it works fine. I decided I wanted a receptionists desk, so I uploaded the pastebin, went to the receptionist desk, got the pastebin.
So I decided that when the receptionis logs in, he/she would edit a file, entitled "problem?"
The problem is, that I don't know how to call to edit that file from Lua, or if there is a way.
Here's the code around the area that I want it at:

...
password = read("*")
if password == "(password)" then
write("password accepted")
sleep(2)
-- edit problem?
sleep(1)
os.shutdown()

elseif password == "(masterpassword)" then
...
Everything works fine, I just don't know how to call to edit that file from Lua. I just basically want the user to edit problem? and then have the computer turn of so he/she can't edit startup.
I'll paste the rest of the code here
Spoiler



term.clear()
term.setCursorPos(1,1)
os.pullEvent = os.pullEventRaw
term.setTextColor(32)
sleep(1)
print(" #")
print(" #		 ##   #	# ######")
print(" #		#  #  #   #  #")
print(" #	   #	# ####   #####")
print(" #	   ###### #  #   #")
print(" #	   #	# #   #  #")
print(" ####### #	# #	# ######")
sleep(1)
print("						####   ####  #####  #####")
print("					   #	# #	# #	# #	#")
print("					   #	  #	# #	# #	#")
print("					   #	  #	# #####  #####")
print("					   #	# #	# #   #  #")
print("						####   ####  #	# #") -- btw this is just LakeCorp ASCII
write("Login Now Loading:")
sleep(1)
write("#")
sleep(1)
write("#")
sleep(1)
write("#")
sleep(1)
write("#")
sleep(1)
write("#:")
sleep(2)
print(" ")
print("Loading Complete!")
print("Welcome LakeCorp Receptionist!")
print("Enter Password")
password = read("*")

if password == "(password)" then
write("Password Accepted")
sleep(2)
--edit problem?
sleep(1)
os.reboot
redstone.setOutput ("left",false)
os.shutdown()
elseif password == "(masterpassword)" then
term.clear()
print("Welcome Laketri, you may edit now!")
sleep(1)
else
write("Inorrect Password")
redstone.setOutput ("back",true)
sleep(2)
term.clear()
print("	   alert")
sleep(25)
os.shutdown()
end
Bubba #2
Posted 03 August 2013 - 10:33 AM
Split into new topic.
Bubba #3
Posted 03 August 2013 - 10:47 AM
You can start the edit program by using the shell.run command.


shell.run("/rom/programs/edit", "problem?")

The first argument is the program you want to run. Any arguments after that are the arguments you want to be passed into the program.
Laketri #4
Posted 03 August 2013 - 03:05 PM
You can start the edit program by using the shell.run command.


shell.run("/rom/programs/edit", "problem?")

The first argument is the program you want to run. Any arguments after that are the arguments you want to be passed into the program.
Thank's, that worked perfectly
PixelToast #5
Posted 03 August 2013 - 03:17 PM
i would suggest you not use a ? in a filename because it is a wildcard character and might make some things freak out
Lyqyd #6
Posted 03 August 2013 - 04:31 PM
Also, for a while now, you can simply pass the whole command-line string, like:


shell.run("/rom/programs/edit problem?")