Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

if with or?

Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-23-2009 18:55
i've seen some examples here that checks between 2 things within an if statement. IE an item that can only be used by 2 certain people, it would check if it was this person or the other person. it wasn't using an access list either. all of my search queries seem to find nothing or too many results, or the word isn't long enough
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-23-2009 18:57
Something like this?

touch_start (integer count)
{
key toucher = llDetectedName(0);
if (toucher == "Person A" || toucher == "Person B";)
{
// ... do stuffs
}
}
Yingzi Xue
Registered User
Join date: 11 Jun 2008
Posts: 144
01-23-2009 19:00
You can use && for AND and || for OR, like this...

From: someone

// if the detected key is equal to known_avatar_key1 OR
// detected key is equal to known_avatar_key2

if (llDetectedKey(0) == known_avatar_key1 || llDetectedKey(0) == known_avatar_key2)
{
// yes, it's one of the two people
}
else
{
// no, it's not one of the two people
}
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-23-2009 19:03
From: Sindy Tsure
Something like this?

touch_start (integer count)
{
key toucher = llDetectedName(0);
if (toucher == "Person A" || toucher == "Person B";)
{
// ... do stuffs
}
}


yeah, that was what i was talking about, but it doesn't seem to work with what i need lol.
i'm trying to check if a vector is between 2 vectors. i want to change the scale of a door only if the result will be smaller than the max size and bigger than the minimum size
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-23-2009 19:17
From: Ruthven Willenov
i'm trying to check if a vector is between 2 vectors.


Something like this then, maybe?

vector gMin = <...>;
vector gMax = <...>;

integer IsBetween (vector size)
{
return (size.x >= gMin.x && size.x <= gMax.x &&
size.y >= gMin.y && size.y <= gMax.y &&
size.z >= gMin.z && size.z <= gMax.z);
}
Yingzi Xue
Registered User
Join date: 11 Jun 2008
Posts: 144
01-23-2009 19:19
Nevermind, was beat to the punch.
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
01-23-2009 19:20
Check the floats of the vectors.
if (size.x < big.x && size.x > small.x) and so on...

Edit: to late on this one.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-23-2009 19:22
need... more... coffee...
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-23-2009 19:24
From: Sindy Tsure
Something like this then, maybe?

vector gMin = <...>;
vector gMax = <...>;

integer IsBetween (vector size)
{
return (size.x >= gMin.x && size.x <= gMax.x &&
size.y >= gMin.y && size.y <= gMax.y &&
size.z >= gMin.z && size.z <= gMax.z);
}


hmm, maybe. i'm making a door that the size can be customized. basically the user holds the mouse button down until they have the scale they want. when they let go, the stretch direction is reversed:

CODE

vector stretch = <0.0,0.0,0.125>;

default
{
touch(integer num)
{
vector scale = llGetScale();
vector pos = llGetPos();
vector test = scale + stretch;
if(test <= <0,0,10> || test >= <0,0,0.01>)//getting type mismatch here, which is why i asked
{
llSetScale(scale+stretch);
llSetPos(pos+(stretch/2)*llGetRot());
}
}

touch_end(integer num)
{
stretch = -stretch;
}
}


when i did it without the if statement, it of course kept moving even though it couldn't scale anymore if i continued to hold it down
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
01-23-2009 19:25
Need to go to bed, 4:23 AM in germany...-_- lol
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-23-2009 19:27
Or, if you're interested in the maximum distance between any two points on the door (the major diagonal), then you might want to do something more like 'if (llVecMag(size) > min && llVecMag(size) < max)'.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
01-23-2009 20:12
It's not really a type mismatch. If you check it with lslint you will see that LSL does not allow you to check if one vector is greater then, equal to or smaller then another vector. The correct answer was what was given, that you have to break it down to the components and compare them.

Example (EDIT: Forgot to add that this will not work or compile)

CODE
default {
touch_start(integer num) {
if (<0,0,9> <= <0,0,10>) {
llOwnerSay("less then or equals");
}
}
}


But you can run a check like this:
CODE
while ( llVecDist( test, <0,0,10>) > 0.01){



I have never tried it and maybe you might want to experiment and see if this will work?
CODE
while ( llVecDist( test, <0,0,10>) > 0.01 ||  llVecDist( test, <0,0,1> ) > 0.01 );
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-23-2009 20:44
hmm, i was thinking about that, i'll have to check it and see

edit: i don't think it will work since the X and Y axis will always be more than 0, so the distance will always be more than 0.01 right?
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
01-24-2009 07:56
Just checked in world and it will work like this:

CODE

vector vecStretch = <0.0, 0.0, 0.125 >;

default {
touch(integer num) {
vector vecNewScale = llGetScale() + vecStretch;
if (vecNewScale.z <= 5 && vecNewScale.z >= 1) {
llSetScale(vecNewScale);
llSetPos(llGetPos() + (vecStretch / 2) * llGetRot());
}
}
touch_end(integer num) {
llOwnerSay((string)llGetScale());
vecStretch *= -1;
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
01-24-2009 07:57
What does it mean for a vector to be "between" two others?

There are several interpretations. One is based solely on vector length. Another is based on whether, when interpreted as a point in space, the point is on the line between the other two. (This latter will nearly always be false, due to floating point issues, unless you allow for discrepancies.) There's another one similar to this but interpreting the vector as an angle rather than a point in space, but that's probably better done using rotations.

And there is a whole family of other interpretations, if you mean only one coordinate, or one of the component angles (or one of the component angles relative to an arbitrary basis).

Apparently, you're only interested in the Z component here, so as mentioned above, just test the Z component.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-24-2009 17:42
that's true lear in this case. but i was hoping to be able to just change the stretch vector if i want it to move and stretch on one of the other axises. but i guess i'll have to tell the script which axis to look at as in jesse's example
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-24-2009 21:02
i changed your version a little jesse, and used llSetPrimitiveParams, so the move and scale would be at the same time. and i also added an else to make the stretch reverse
CODE

vector vecStretch = <0.0, 0.0, 0.125 >;

default {
touch(integer num) {
vector vecNewScale = llGetScale() + vecStretch;
if (vecNewScale.z <= 10 && vecNewScale.z >= .125) {
llSetPrimitiveParams([PRIM_SIZE,vecNewScale,
PRIM_POSITION,llGetPos() + (vecStretch / 2) * llGetRot()]);
}
else{vecStretch *= -1;}
}
touch_end(integer num) {
llOwnerSay((string)llGetScale());
vecStretch *= -1;
}
}


and then i played a little more and was like hmm, what about blinds? blinds that i've seen scale and the texture stretches or squishes with it, not very realistic, so i did this using path cut

CODE

vector vecCut = <0.0125, -0.0125, 0.0 >;

default {
state_entry()
{
llSetPrimitiveParams([
PRIM_TYPE, PRIM_TYPE_BOX, 0, <0.0, 1.0, 0.0>, 0.949970, <0.25, 0.25, 0.0>, <1.0, 1.0, 0.0>, ZERO_VECTOR,
PRIM_SIZE, <0.01, 1.0, 1.0>,
PRIM_ROTATION, <0.70711, 0.0, 0.0, 0.70711>,
PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 1.0,
PRIM_TEXTURE, 0, "f54a0c32-3cd1-d49a-5b4f-7b792bebc204", <1.0, 1.0, 0.0>, ZERO_VECTOR, -1.570844,
PRIM_TEXTURE, 1, "579320fb-156c-7bc0-0f40-8d68663f2109", <1.0, 20.0, 0.0>, ZERO_VECTOR, -1.570844,
PRIM_TEXTURE, 2, "579320fb-156c-7bc0-0f40-8d68663f2109", <1.0, 20.0, 0.0>, ZERO_VECTOR, -1.570844,
PRIM_TEXTURE, 3, "579320fb-156c-7bc0-0f40-8d68663f2109", <1.0, -20.0, 0.0>, ZERO_VECTOR, -1.570844,
PRIM_TEXTURE, 4, "579320fb-156c-7bc0-0f40-8d68663f2109", <1.0, -20.0, 0.0>, ZERO_VECTOR, -1.570844,
PRIM_TEXTURE, 5, "f54a0c32-3cd1-d49a-5b4f-7b792bebc204", <1.0, 1.0, 0.0>, ZERO_VECTOR, -1.570844,
PRIM_TEXTURE, 6, "f54a0c32-3cd1-d49a-5b4f-7b792bebc204", <1.0, 1.0, 0.0>, ZERO_VECTOR, -1.570844]);
}
touch(integer num) {
list params = llGetPrimitiveParams([PRIM_TYPE]);
vector vecNewCut = llList2Vector(params,2) + vecCut;
if (vecNewCut.x <= .475 && vecNewCut.x >= 0.0) {
llSetPrimitiveParams([PRIM_TYPE,PRIM_TYPE_BOX,0,vecNewCut,0.95,<0.25, 0.25, 0.0>,<1,1,0>,<0,0,0>]);
}
else{vecCut *= -1;}
}
touch_end(integer num) {
vecCut *= -1;
}
}