@MysticT - Great! I did not know that getn would not work for strings but it sounds like #table would work better than getn even if it wasn't so thanks for the heads up. A much more elegant solution. I implemented your suggestion but it still wasn't working so much but then I tried this:
if k1 == 21 --y
then
table.insert(userlist, newusername)
userlist[newusername] = {}
table.insert(userlist[newusername], "password")
userlist[newusername].password = newpassword
table.insert(userlist[newusername], "adminstatus")
userlist[newusername].adminstatus = admin
home()
elseif k1 == 49 then --n
newuser()
end
and with the inclusion of the insert.table lines I got it functioning properly. Thanks!!! However now it seems I've created a new problem that I'm up against now where if I go through and enter in everything properly it all works fine and logs me in as the username, however if, after I register the new user, if I enter the password incorrectly 3 times it then does print("Too many failed attempts blah blah") and returns to the login function (as it should) but when I type in the username again it closes the program and returns to command prompt. Debugging is like playing a mole game huh? :)/>/>
@OminousPenguin -
As this program is MOSTLY (although having a neat little user database on my server is also useful) to teach me to program after a 15 year hiatus I welcome any and all suggestions / tips to improve efficiency or what have you! I was going to actually create a thread asking for just pure and simple recommendations such as this as I'm always a fan of limiting the focus of individual threads but thank you for your input none the less. But while we're here lets go down your suggestions:
1) I see your point and calling a function too often with no actual change or results is never a good idea and it definitely seems that way now, such as here:
function home()
homescreen()
if #userlist == 0 and status == "Logged Out"
then
admin = true
function newuser()
homescreen()
if admin == true
then
print("Please register Admin:")
write("Enter Username:")
else
print("Please register User:")
write("Enter Username:")
end
Obviously homescreen() has just been called at the beginning of home() and then immediately after in newuser() without any screen changes, however I plan to add in functionality that will call newuser() (and other such functions) at other times which will require a homescreen() flush so to speak. Granted I may have missed an occurrance that is currently and will forever be superfluous so feel free to cite specific example! Or maybe I just missed your point entirely :)/>/> Aside: It may look strange because it wasn't till after I wrote most of this code that I realized you do not have to call a function immediately after ending it (derp!) which is how every example worked in the tutorial I looked at so the function organization is a bit funky. If I were to re write this code (and I probably will do this at some point) I would have functions such as newuser() and login() defined outside of any other functions.
2) Thank's for the heads up! I had not noticed that (mostly because the code as it was wouldn't even run that far and I was preoccupied with the previous error!) but it is now fixed! login() is now called after the nil check and it works as intended (for the most part; see earlier section to MysticT about new bug…)
3) Valid point. changed the call to x in line 85 to 3-a which is all x is anyways as you point out.
4) I'm guessing you mean that some of my if statements could be made shorter with a for or while loop? Correct me if I'm wrong. If that is the case, in my mind the if statement seems simpler I suppose? But lets challenge that. Give me an example of where you would use a loop instead of what I have but don't say anything about how you would implement and I will challenge myself to make it more efficient by using a loop (best way for me to learn eh?)
Again thanks for your suggestions! I always welcome constructive criticism! Especially early on to help defeat long term bad habits. I might make this into a separate "Tear my code apart!!" thread in order to avoid OT discussions so reply there if you could!