Page 1 of 1

Texture changer with avatar sensor

Posted: Thu Aug 19, 2021 4:57 pm
by Tess Juel
Here's a nifty little snippet I wrote for Michael in response to this thread.
What it does, is change the texture of an object whenever somebody comes near it:

Code: Select all

float distance=5.0; // Sets the distance the texture changes at
// Change txt1 to the name of the texture when no avatar is near and
// txt2 to the name of the texture when an avatar is near
list textures=["txt1","txt2"]; 
integer txtno;

default{

    state_entry(){
        llSensorRepeat("",NULL_KEY,AGENT,distance,PI,0.1);
    }

     sensor( integer detected ){
        if(!txtno){
            txtno=!txtno;
            llSetTexture(llList2String(textures,txtno), ALL_SIDES);
        }
    }

     no_sensor(){
        if(txtno){
            txtno=!txtno;
            llSetTexture(llList2String(textures,txtno), ALL_SIDES);
        }
    }

}
Hope you find it useful!

Re: Texture changer with avatar sensor

Posted: Thu Aug 19, 2021 5:05 pm
by Tess Juel
Come to think of it, this snippet can be modified to do lots of other things too. So here's a more generic version:

Code: Select all

float distance=5.0; // Sets the distance the texture changes at
integer avatarNear;

default{

    state_entry(){
        llSensorRepeat("",NULL_KEY,AGENT,distance,PI,0.1);
    }

     sensor( integer detected ){
        if(!avatarNear){
            avatarNear=!avatarNear;
            // insert whatever code you want executed when somebody dares to come near
        }
    }

     no_sensor(){
        if(avatarNear){
            avatarNear=!avatarNear;
           // insert whatever code you want executed when they come to their senses and leave
        }
    }

}

Re: Texture changer with avatar sensor

Posted: Sat Aug 21, 2021 1:36 pm
by Graham Mills
Perhaps worth mentioning that there are/were some LSL script generators:

Re: Texture changer with avatar sensor

Posted: Sat Aug 21, 2021 9:42 pm
by Michael Timeless
Graham
Thank you for posting these. One of the things I often wonder with script generators is (and the top two don't) is can they allow an object to sense an avatar and then perform an action?

An example could trigger a cascade action (i.e. Avatar approaches door, door senses avatar, door opens. Second sensor detects door opening triggers object moving (skeleton pops out of crypt/ or another door opens), third sensor detects the skeleton/door, opens another door (to lead the avatar in another direction). Although I suppose you could use sensors for all of that. Without the "cascade effect," it requires the specific avatar to be in a specific place to trigger the next event, which could break the sequence.

If I'm making any sense... :ugeek:

Re: Texture changer with avatar sensor

Posted: Sat Aug 21, 2021 10:07 pm
by Graham Mills
I think you're getting beyond the remit of the simple script generators although Scriptastic (modelled on Scratch but now probably abandonware) handles avatar collisions that can be coupled to chat so in principle they could trigger listeners in downstream objects that in turn triggered the further changes you describe. There is, however, no means to program the listeners in Scriptastic. The defunct FL2SL, also Scratch-influenced, would probably have been more functional/useful although it is a good while since I used it.

https://greenbushlabs.com/scriptastic/

Michael Timeless wrote:
Sat Aug 21, 2021 9:42 pm
Graham
Thank you for posting these. One of the things I often wonder with script generators is (and the top two don't) is can they allow an object to sense an avatar and then perform an action?

An example could trigger a cascade action (i.e. Avatar approaches door, door senses avatar, door opens. Second sensor detects door opening triggers object moving (skeleton pops out of crypt/ or another door opens), third sensor detects the skeleton/door, opens another door (to lead the avatar in another direction). Although I suppose you could use sensors for all of that. Without the "cascade effect," it requires the specific avatar to be in a specific place to trigger the next event, which could break the sequence.

If I'm making any sense... :ugeek:

Re: Texture changer with avatar sensor

Posted: Sat Aug 21, 2021 10:30 pm
by Michael Timeless
How Ironic. I was just coming back to post a video I found on Scriptastic. LOL. Thanks Graham.

Re: Texture changer with avatar sensor

Posted: Sun Aug 22, 2021 1:18 am
by Christine Nyn
Michael Timeless wrote:
Sat Aug 21, 2021 9:42 pm
...An example could trigger a cascade action (i.e. Avatar approaches door, door senses avatar, door opens. Second sensor detects door opening triggers object moving (skeleton pops out of crypt/ or another door opens), third sensor detects the skeleton/door, opens another door (to lead the avatar in another direction). Although I suppose you could use sensors for all of that. Without the "cascade effect," it requires the specific avatar to be in a specific place to trigger the next event, which could break the sequence...
An interesting thought Michael, but you wouldn't actually need the cascade for this particular example. The simple detection of the avatar could initiate a timed sequence of events controlled by one master script. Assuming the triggering avatar takes the implied invitation of another door opening a further detection and sequence could then take place and you could repeat that with variations as much as you wished. It almost sounds as if you might be wanting to re-create the Ghost Train ride that many fairs used to have, and which Disney World has a version of in their Magic Castle.

Re: Texture changer with avatar sensor

Posted: Sun Aug 22, 2021 1:32 am
by Michael Timeless
Christine

Actually I was thinking of a door that when you opened it, triggered a sliding door that drops the floor out from under the user. Not sure if it would even require a sensor, just let the act of opening the standard door, trigger the sliding door.

Been a few decades since Disney world...lol.

Re: Texture changer with avatar sensor

Posted: Sun Aug 22, 2021 1:37 am
by Christine Nyn
Michael Timeless wrote:
Sun Aug 22, 2021 1:32 am
Christine

Actually I was thinking of a door that when you opened it, triggered a sliding door that drops the floor out from under the user. Not sure if it would even require a sensor, just let the act of opening the standard door, trigger the sliding door.

Been a few decades since Disney world...lol.
So... an enforced choice?

Re: Texture changer with avatar sensor

Posted: Mon Aug 23, 2021 5:13 pm
by Michael Timeless
I guess I could take the grandkids or great grandkids. The "kids" are in their 30s