|
Carbon Philter
Registered User
Join date: 4 Apr 2008
Posts: 165
|
06-27-2009 16:58
I'm trying to set up a condition where vehicle use is permitted by either the owner or others in the same group to which the vehicle is set.
I know my script is messy but I can't get my head round the if/else process and nesting, so I set it up in separate steps but it simply refuses to work as I expect it to.
It's set with an either/or condition for ownership/group membership as true to permit operation. Using an alt not in the same group to test, I get the report that both ownership and active group are false, but it then reports that authorisation is granted, when it should not. I've played with llSameGroup and llDetectedGroup and can get neither to work as I expect.
Can anyone point out my flawed logic, please?
Thanks.
Script as follows:
integer group; integer owner; key person;
default { state_entry() //when script begins { llSetText("Try me",< 255,255,0>,1); } touch_start(integer x) //when touched { person = llDetectedKey(0); // if (llSameGroup(person)) //if same group as object if (llDetectedGroup(x)) { group = 1; llSetText("g1",< 255,0,0>,1); llSleep(1.0); } else //else if person is not in group { group = 0; llSetText("g0",< 255,0,0>,1); llSleep(1.0); } if (llGetOwner() != person) { llSetText("o0",< 255,0,0>,1); owner = 0; llSleep(1.0); } else { owner = 1; llSetText("o1",< 255,0,0>,1); llSleep(1.0); } if (owner = 1 || group = 1) { llSetText("Hey, it's yours to operate! Welcome",< 0,255,0>,1); } else { llSetText("It's not yours and you're not in the appropriate group to operate this vehicle",< 255,0,0>,1); } llSleep(3.0); //wait 3 seconds llResetScript(); //make script start again } }
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
06-27-2009 18:01
when you go into the touch event it gives you a TOTAL of the number of people touching (which you save as "x"  that total actually refers to an array (the only real arrays in LSL) with information about each person that touched the object before the event code fires... lsl exclusively uses zero based arrays, so if there is 1 TOTAL that means you access the data for that toucher using the first index which is actually 0. essentially, you either need to use llDetected*( 0 ), or loop through them using --x. a compacted test would be if (llDetectedGroup( 0 ) | llDetectedKey( 0 ) == llGetOwner()){ //authorised }else{ // not allowed } your simplest loop would be do{ --x //tests }while (x); in the vehicle function you'd test (llSameGroup( x ) | x == llGetOwner()) where x = llAvatarOnSitTarget()
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
06-28-2009 01:56
The problem in the original script is this line.
if (owner = 1 || group = 1)
should be
if (owner == 1 || group == 1)
Edit - In addition to what Void said.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
06-28-2009 05:38
hah, can't believe I missed that... it may help to put constants on the left when doing conditionals like (1 == variable) so that the compiler will spit an error at you if you forget of of the equal signs.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Carbon Philter
Registered User
Join date: 4 Apr 2008
Posts: 165
|
06-28-2009 05:54
Thank you both for help.
Void - I will need to study your comments further to get my head round it. I know the original is not a thing of beauty and the ultimate aim is to be as economic as possible but so far it has to be very small steps.
Bev - thanks. Your comment led to a solution! I tried it with the llDetectedGroup with no success but when I commented that out and activated the llSameGroup line it works as I wanted.
Just for clarification, if I had put (owner = TRUE || group = TRUE) instead of using the boolean value would that have resolved the original glitch?
Thanks again guys.
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
06-28-2009 06:33
From: Carbon Philter Just for clarification, if I had put (owner = TRUE || group = TRUE) instead of using the boolean value would that have resolved the original glitch?
(owner = TRUE || group = TRUE) is identically equal to TRUE so you would actually write: if (TRUE) statement; This makes no sense; it is the same as writing the statement without any 'if' clause
_____________________
From Studio Dora
|
|
Carbon Philter
Registered User
Join date: 4 Apr 2008
Posts: 165
|
06-28-2009 08:06
Dora, I don't quite see how (owner = TRUE || group = TRUE) is identically equal to TRUE. I can see that (owner = TRUE && group = TRUE) is the same as (TRUE) statement, but I'm trying to determine if one or the other conditions is FALSE - I want to be able to operate the item I own even though I don't have the specific Group tag active so from my take I need the either/or statement to cover the owner check. I'm not refusing to believe you - I'll just have to go think on it some more. 
|
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
06-28-2009 09:13
Lets see if i can clarify.
owner = TRUE is an assignment After this statement whatever value owner had previously has been overwritten and owner now has the value of TRUE.
Owner == TRUE is a comparison it compares the left and right sides and returns a TRUE or FALSE value depending on the result.
Therefore if(owner = TRUE || group = TRUE) sets the values of owner and group to TRUE so the statement is in effect if(TRUE || TRUE) which always returns TRUE.
if(owner == TRUE || group == TRUE) tests first if the value of owner is TRUE then if the value of group is TRUE then or's the results of the comparison to give the final result.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
06-28-2009 10:25
From: Carbon Philter Void - I will need to study your comments further to get my head round it. I know the original is not a thing of beauty and the ultimate aim is to be as economic as possible but so far it has to be very small steps. I was a bit tired when I wrote that, so let me make it easier... touch_start integer vIntTotal ){ vIntTotal is how many people are in a list of people that touched the object for example lets say there are three... lists are zero index based (zero is the first number) so 0, 1, and 2 are all valid targets in that list (that can be accessed with the llDetected* functions) but 3 is past the end of the list (because zero is the first element) so if (llDetectedGroup(x)) should return TRUE if the object is set to group "None" and false otherwise, regardless of who touches it.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|