5 posts
Posted 27 December 2014 - 07:28 PM
Install: pastebin get hsaUDfJu nas
Note: When settings are changed, the app must be restarted in order for changes to take effect.
qNASNetwork Accessible Storage for ComputerCraft.qNAS allows file sharing between a cloud device and a client device; you are able to set the server to serve a custom directory, as well as the root directory. The program also allows password protection [enabled by setting the pass variable within the settings file].
All code is at
http://pastebin.com/hsaUDfJu.
ScreenshotsFeedback needed.
Edited on 27 December 2014 - 07:42 PM
11 posts
Posted 13 March 2015 - 04:49 PM
For some reason it always says "Server not found". Yes I've set the label in the config and yes I am typing the name correctly.
350 posts
Posted 14 March 2015 - 03:29 PM
Tip: if you want to exit your program with an error (i also do this sometimes) At least create a error handler and if the error code is like "ok" or "exit" (anything you want, really) it will run a code block. For example:
function main()
print("Place in main() ALL of your code")
error("ok")
end
ok, err = pcall(main)
if not ok then --if the handler trows an error
if err == "ok" then --if the error is "ok" (error from the second line of the main function) then it will run the following code:
term.clear()
term.setCursorPos(1,1)
print("Thank you for using this program")
end
end
EDIT: My bad, this is bad code above. If you want to exit a program at any state you should place:
error()
Thank you apemanzilla :P/>
Edited on 15 March 2015 - 10:03 AM
1610 posts
Posted 15 March 2015 - 03:48 AM
Tip: if you want to exit your program with an error (i also do this sometimes) At least create a error handler and if the error code is like "ok" or "exit" (anything you want, really) it will run a code block. For example:
function main()
print("Place in main() ALL of your code")
error("ok")
end
ok, err = pcall(main)
if not ok then --if the handler trows an error
if err == "ok" then --if the error is "ok" (error from the second line of the main function) then it will run the following code:
term.clear()
term.setCursorPos(1,1)
print("Thank you for using this program")
end
end
…What? That just defeats the purpose of pcall. Why use the error("ok") part at all? If it exits WITHOUT throwing an error, ok will be false, meaning that no error occurred, but if an error does occur, it will be true.
350 posts
Posted 15 March 2015 - 10:58 AM
Tip: if you want to exit your program with an error (i also do this sometimes) At least create a error handler and if the error code is like "ok" or "exit" (anything you want, really) it will run a code block. For example:
function main()
print("Place in main() ALL of your code")
error("ok")
end
ok, err = pcall(main)
if not ok then --if the handler trows an error
if err == "ok" then --if the error is "ok" (error from the second line of the main function) then it will run the following code:
term.clear()
term.setCursorPos(1,1)
print("Thank you for using this program")
end
end
…What? That just defeats the purpose of pcall. Why use the error("ok") part at all? If it exits WITHOUT throwing an error, ok will be false, meaning that no error occurred, but if an error does occur, it will be true.
In the function "main" i called an error, wich will be "ok". When the pcall receives the error, it will check if the error name is "ok" ( at least i should use string.sub() to check only the 2 last characters of the error code). But if the error is "ok" it will run that code. And this was just an example, in more complex code its easier to exit the program this way.
EDIT: Ok i think i got what you are saying. If no parameter is given in the error function the program will exit right away.
Edited on 15 March 2015 - 10:01 AM
1610 posts
Posted 15 March 2015 - 01:42 PM
Tip: if you want to exit your program with an error (i also do this sometimes) At least create a error handler and if the error code is like "ok" or "exit" (anything you want, really) it will run a code block. For example:
function main()
print("Place in main() ALL of your code")
error("ok")
end
ok, err = pcall(main)
if not ok then --if the handler trows an error
if err == "ok" then --if the error is "ok" (error from the second line of the main function) then it will run the following code:
term.clear()
term.setCursorPos(1,1)
print("Thank you for using this program")
end
end
…What? That just defeats the purpose of pcall. Why use the error("ok") part at all? If it exits WITHOUT throwing an error, ok will be false, meaning that no error occurred, but if an error does occur, it will be true.
In the function "main" i called an error, wich will be "ok". When the pcall receives the error, it will check if the error name is "ok" ( at least i should use string.sub() to check only the 2 last characters of the error code). But if the error is "ok" it will run that code. And this was just an example, in more complex code its easier to exit the program this way.
EDIT: Ok i think i got what you are saying. If no parameter is given in the error function the program will exit right away.
What I was asking was, why add the "error('ok')" line? You can still detect if there wasn't an error without needing to call for and test for that.
For example:
function main()
--# Do stuff
end
local ok, error = pcall(main)
if ok then
term.clear()
term.setCursorPos(1,1)
print("Thank you for using this program")
else
--# Handle error
end
This code would do the exact same thing as yours.
Edited on 15 March 2015 - 12:44 PM
350 posts
Posted 15 March 2015 - 05:51 PM
Tip: if you want to exit your program with an error (i also do this sometimes) At least create a error handler and if the error code is like "ok" or "exit" (anything you want, really) it will run a code block. For example:
function main()
print("Place in main() ALL of your code")
error("ok")
end
ok, err = pcall(main)
if not ok then --if the handler trows an error
if err == "ok" then --if the error is "ok" (error from the second line of the main function) then it will run the following code:
term.clear()
term.setCursorPos(1,1)
print("Thank you for using this program")
end
end
…What? That just defeats the purpose of pcall. Why use the error("ok") part at all? If it exits WITHOUT throwing an error, ok will be false, meaning that no error occurred, but if an error does occur, it will be true.
In the function "main" i called an error, wich will be "ok". When the pcall receives the error, it will check if the error name is "ok" ( at least i should use string.sub() to check only the 2 last characters of the error code). But if the error is "ok" it will run that code. And this was just an example, in more complex code its easier to exit the program this way.
EDIT: Ok i think i got what you are saying. If no parameter is given in the error function the program will exit right away.
What I was asking was, why add the "error('ok')" line? You can still detect if there wasn't an error without needing to call for and test for that.
For example:
function main()
--# Do stuff
end
local ok, error = pcall(main)
if ok then
term.clear()
term.setCursorPos(1,1)
print("Thank you for using this program")
else
--# Handle error
end
This code would do the exact same thing as yours.
That would print "thank you, etc" at the end of the program.
When i call error() is so i can exit the code whenever i want. For example:
function main()
print("hello")
sleep(1)
error("ok") --#if i call an error here i can stop the program exactly here, and no more code will be ran
print("testing")--#this code will not run because i exited the program at the error("ok")
sleep(1)
end
local ok, error = pcall(main)
if not ok and error == "ok" then
term.clear()
term.setCursorPos(1,1)
print("Thank you for using this program")
end
The idea of calling the error is to exit from the program from everywhere i want. Not only at the end of the program.