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

Computercraft System boot disk only thing? help?

Started by spysean1499, 26 August 2015 - 10:57 AM
spysean1499 #1
Posted 26 August 2015 - 12:57 PM
Hey.. i dont know if I put this in the right place but..

I have tried to learn lua but i allways fail (cus stuff keeps changeing and stuff) anyway i was wondering if thare is anyone who could help make a program for me
that dose the following (soz 4 bad desription)

What i need is when you type in edit <your program> or delete <your program> or something it will reqire a password also another usefull thing would be could anyone
who dose this mabie make it so it only boots of the disk.. another thing (sorry) is that mabie if thare isnt a redstone input the PCs wont work… or somthing liek if thare is no power then it wont boot… IDK

ONLY 2 MORE REQUESTS

a) could you mabie put this on a OS (that boots from the system disk) and is just made for files, running programs and email (and passwords to do everything of couse)

b)could you mabie have 2 passwords 1 is the basic one that allows you to create files (just not startup file), check email ect (NO DELETING, MOVEING OR COPYING SYSTEM FILES) and one account
for the admin so somewon can have admin controlls… mabie a seprate disk client that is reqired to use admin (like mabie a file that is looked for when system starts up? and if found gives you option for
ADMIN LOGIN)

I am asking because i would like to use this on my jurrasic park project (currnetly suspended until I get this done cus this is the next step) the other progect is for my greenfield RP i d with my frinds (and stuff) i am haveing probloms with my bussness in greenfeild… people keep deleteing the startup file or makeing it dlete everyhing in the system it is getting really anoying… me and them only know some basics and none of them kow how to do this…
Exerro #2
Posted 26 August 2015 - 02:27 PM
Ask a pro is generally used for asking for help with specific bits of code not requesting people write things for you.

Anyway, here's some advice/information about doing it yourself:

When you try and delete a file, you do so by using the fs library (fs.delete). The same goes for editing, moving, and, well, anything regarding files or directories. If you want to give custom behaviour to the library (for example requiring a password to delete a file), you can override the individual functions in the library. For example, this will ask for a password every time you try to delete any file:

local oldDelete = fs.delete
local password = "1234"
function fs.delete( file )
    print "Please enter a password to delete the file"
    if read() == password then
        oldDelete( file )
    end
end

What that code does is this:
  1. make a backup of the function so it can be called later
  2. override the function with its own code which does:
    1. prints a string letting the user know they need to enter a password
    2. gets the user's input with read()
    3. checks that what they entered is equal to the password, and if it is, deletes the file using the backed up function
You can use a similar approach with all the fs functions, for example fs.open() and fs.move().

The documentation of the fs library is here.
spysean1499 #3
Posted 28 August 2015 - 06:29 AM
THANK YOU… but were can i put this… like weres the proper place? I ave a lot of trouble understanding things (my teacher &amp; mother say its my ortisem) so i have trouble with lua… but i am learning… thank you… also is
thare a fs command for editing? and again… THANK YOU!
Edited on 28 August 2015 - 04:54 AM
spysean1499 #4
Posted 28 August 2015 - 07:05 AM
just tried the code.. and i had trouble makeing it work this is how i used it
—————————————————————————————————————

print"PASSWORD REQIRED"
os.sleep(1)

local oldDelete = fs.delete
local password = "1234"
function fs.delete( file )
print "Please enter a password to delete the file"
if read() == password then
oldDelete( file )
end
end