|
Dante Breck
Spellchek Roxs
Join date: 29 Oct 2006
Posts: 113
|
04-08-2008 11:18
Ok, I have the following as a really simple lock for a door. It uses a list of names in the access list to determine who is allowed and who is not allowed. However it finds whoever touches it in the access list regardless of whether they appear in the list or not and its driving me nuts. I have intentionally left my name out of the access list and it still opens for me. I have also tried with an alt that is definitely not in the access list and it still opens. I am a coding neophyte so please shoot with rubber bullets. Help?
list Access = ["Bob Smith", "Crashalot Linden"];
integer authorized; string name;
checkAuth(key agent) { name = llKey2Name(llDetectedKey(0)); llWhisper(0, name + " was detected when clicked"); authorized = FALSE; // check for authorization if (llListFindList(Access, [name]) != -1) { authorized = TRUE; llWhisper(0, "name found in authorization list"); } // tell person they are authorized, then reset if (authorized = TRUE) { llWhisper(0, name + " You are authorized"); llMessageLinked(LINK_SET, 0, "door", ""); authorized = FALSE; } }
|
|
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
|
04-08-2008 11:19
// tell person they are authorized, then reset if (authorized = TRUE)
should be
if (authorized == TRUE)
I believe. The original is stating it as true, while the second is checking the truthfulness
_____________________
Tutorials for Sculpties using Blender! Http://www.youtube.com/user/BlenderSL
|
|
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
|
04-08-2008 11:22
ignore this post
_____________________
Tutorials for Sculpties using Blender! Http://www.youtube.com/user/BlenderSL
|
|
Dante Breck
Spellchek Roxs
Join date: 29 Oct 2006
Posts: 113
|
04-08-2008 11:35
Never mind .. I looked at it again. I don't know why I was using two if statements .. I compressed it all into one and lo and behold it worked.
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
04-09-2008 22:01
From: Dante Breck Never mind .. I looked at it again. I don't know why I was using two if statements .. I compressed it all into one and lo and behold it worked. Do pay attention to what Keira is saying though, when testing in conditional statements, you must use ==, not =. It WILL compile, but the conditional statement will always return true, even if the statement is false.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
04-10-2008 00:45
From: Johan Laurasia Do pay attention to what Keira is saying though, when testing in conditional statements, you must use ==, not =. It WILL compile, but the conditional statement will always return true, even if the statement is false. ...unless the value being assigned evaluates to false for the type being assigned. For example, this should evaluate the else branch: integer myInt; if (myInt = FALSE) { // Not executed } else { // executed }
This is because an assignment itself has a value that can be used in other expressions, such as a=b=c or the much praised myList=(myList=[])+... hack.
|