172 posts
Location
United States
Posted 04 March 2014 - 03:57 PM
So… BombBloke helped me with getting the username password and permissions system up… but i'm having a problem checking the permissions…
here is the relevant code
local function checkUsrNamePerm()
while (not users[uName]) or users[uName].permissions ~= "admin" or users[uName].permissions ~= "moderator" do
term.clear()
term.setCursorPos(1, 1)
textutils.slowPrint("Enter username for verification", 25)
uName = read()
if (not users[uName]) or users[uName].permissions ~= "admin" or users[uName].permissions ~= "moderator" then
print("You don't have enough permissions! Please try again.")
else
break
end
end
end
Here is the full code…
http://pastebin.com/JJGSwScm
7083 posts
Location
Tasmania (AU)
Posted 04 March 2014 - 04:16 PM
"uName" is defined as local to the whole script. Meaning that the value assigned to it when checkUNamePasswd() is called persists after that function finishes, so when it's time to call checkUsrNamePerm(), it's already set to a valid username and so that loop does nothing much.
I'd recommend placing copies of line 15:
local uName
… as the first lines in each of those two functions, then removing the original. In this way the variable will be automatically cleared when either function finishes, as opposed to when the entire script finishes.
1281 posts
Posted 04 March 2014 - 04:18 PM
When you ask for help, please provide some details on what's wrong. Don't just say "but im having a problem". What is the probelm, what happens, any errors, what?
172 posts
Location
United States
Posted 04 March 2014 - 04:51 PM
When you ask for help, please provide some details on what's wrong. Don't just say "but im having a problem". What is the probelm, what happens, any errors, what?
Um… look…
So… BombBloke helped me with getting the username password and permissions system up…
but i'm having a problem checking the permissions…here is the relevant code
local function checkUsrNamePerm()
while (not users[uName]) or users[uName].permissions ~= "admin" or users[uName].permissions ~= "moderator" do
term.clear()
term.setCursorPos(1, 1)
textutils.slowPrint("Enter username for verification", 25)
uName = read()
if (not users[uName]) or users[uName].permissions ~= "admin" or users[uName].permissions ~= "moderator" then
print("You don't have enough permissions! Please try again.")
else
break
end
end
end
Here is the full code…
http://pastebin.com/JJGSwScm
172 posts
Location
United States
Posted 04 March 2014 - 05:04 PM
"uName" is defined as local to the whole script. Meaning that the value assigned to it when checkUNamePasswd() is called persists after that function finishes, so when it's time to call checkUsrNamePerm(), it's already set to a valid username and so that loop does nothing much.
I'd recommend placing copies of line 15:
local uName
… as the first lines in each of those two functions, then removing the original. In this way the variable will be automatically cleared when either function finishes, as opposed to when the entire script finishes.
So… when i try the checkUNamePerm() function it keeps infinitely looping when i input a username that has valid permissions…
for some reason it won't break out of the function
1281 posts
Posted 04 March 2014 - 05:05 PM
you don't get it… How are we supposed to know what the problem is? Does it not work at all? Does it like Bomb pointed out just check the same user over and over? Does it error? You need to tell us what you expect it to do, which it dosen't do.
So… when i try the checkUNamePerm() function it keeps infinitely looping when i input a username that has valid permissions…
for some reason it won't break out of the function
This, is what im asking for.
Your function looks like this now, right?
local function checkUsrNamePerm()
local uName
while (not users[uName]) or users[uName].permissions ~= "admin" or users[uName].permissions ~= "moderator" do
term.clear()
term.setCursorPos(1, 1)
textutils.slowPrint("Enter username for verification", 25)
uName = read()
if (not users[uName]) or users[uName].permissions ~= "admin" or users[uName].permissions ~= "moderator" then
print("You don't have enough permissions! Please try again.")
else -- this is completely redundant btw
break
end
end
end
Edited on 04 March 2014 - 04:14 PM
7083 posts
Location
Tasmania (AU)
Posted 04 March 2014 - 11:57 PM
users[uName].permissions ~= "admin" or users[uName].permissions ~= "moderator"
to:
(users[uName].permissions ~= "admin" and users[uName].permissions ~= "moderator")
172 posts
Location
United States
Posted 05 March 2014 - 04:15 PM
users[uName].permissions ~= "admin" or users[uName].permissions ~= "moderator"
to:
(users[uName].permissions ~= "admin" and users[uName].permissions ~= "moderator")
That worked perfectly! thank you…
i rewrote my code so now the function at line 192 doesn't work correctly… it is supposed to keep the program from quitting after completing an action…
Edited on 05 March 2014 - 03:16 PM
7083 posts
Location
Tasmania (AU)
Posted 05 March 2014 - 09:41 PM
I'm afraid the only paste you've provided goes up to line 180.
686 posts
Posted 05 March 2014 - 09:56 PM
Not a solution to whatever problem you're having, but you may find it easier and more flexible to make users[uName].permissions a table against which you check whether a given permission is true or false, ie:
if users[uName] ~= nil then
if not (users[uName].permissions["admin"] == true) or not (users[uName].permissions["moderator"] == true) then
print("You do not have enough permissions! Please try again.")
end
end
172 posts
Location
United States
Posted 05 March 2014 - 10:29 PM
I'm afraid the only paste you've provided goes up to line 180.
hrm… take a look at the bitbucket code here:
https://bitbucket.or...l.lua?at=masterit's at line 204 now… i realize i need to push a new fix to the code
nvrmind… i already fixed what i saw.. :P/>
Edited on 05 March 2014 - 09:29 PM