Texture changer with avatar sensor

Creating scripts
Post Reply
User avatar
Tess Juel
Posts: 267
Joined: Sun Sep 11, 2016 4:24 pm
Has thanked: 249 times
Been thanked: 438 times

Texture changer with avatar sensor

Post 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!
These users thanked the author Tess Juel for the post (total 5):
Kimm StarrMichael TimelessZyzzyx QinanChristine NynSnoots Dwagon
User avatar
Tess Juel
Posts: 267
Joined: Sun Sep 11, 2016 4:24 pm
Has thanked: 249 times
Been thanked: 438 times

Re: Texture changer with avatar sensor

Post 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
        }
    }

}
These users thanked the author Tess Juel for the post (total 5):
Ilan TochnerMichael TimelessZyzzyx QinanGraham MillsSnoots Dwagon
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Texture changer with avatar sensor

Post by Graham Mills »

Perhaps worth mentioning that there are/were some LSL script generators:
These users thanked the author Graham Mills for the post (total 3):
Ilan TochnerMichael TimelessChristine Nyn
User avatar
Michael Timeless
Posts: 113
Joined: Thu Sep 24, 2015 5:13 am
Location: Crestwood, Illinois
Has thanked: 393 times
Been thanked: 153 times
Contact:

Re: Texture changer with avatar sensor

Post 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:
These users thanked the author Michael Timeless for the post:
Christine Nyn
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Texture changer with avatar sensor

Post 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:
Last edited by Graham Mills on Sun Aug 22, 2021 9:13 am, edited 1 time in total.
These users thanked the author Graham Mills for the post:
Michael Timeless
User avatar
Michael Timeless
Posts: 113
Joined: Thu Sep 24, 2015 5:13 am
Location: Crestwood, Illinois
Has thanked: 393 times
Been thanked: 153 times
Contact:

Re: Texture changer with avatar sensor

Post by Michael Timeless »

How Ironic. I was just coming back to post a video I found on Scriptastic. LOL. Thanks Graham.
These users thanked the author Michael Timeless for the post:
Graham Mills
User avatar
Christine Nyn
Posts: 71
Joined: Sat Mar 07, 2020 10:20 pm
Has thanked: 218 times
Been thanked: 126 times

Re: Texture changer with avatar sensor

Post 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.
Last edited by Christine Nyn on Sun Aug 22, 2021 1:41 am, edited 1 time in total.
These users thanked the author Christine Nyn for the post (total 2):
Michael TimelessGraham Mills
User avatar
Michael Timeless
Posts: 113
Joined: Thu Sep 24, 2015 5:13 am
Location: Crestwood, Illinois
Has thanked: 393 times
Been thanked: 153 times
Contact:

Re: Texture changer with avatar sensor

Post 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.
User avatar
Christine Nyn
Posts: 71
Joined: Sat Mar 07, 2020 10:20 pm
Has thanked: 218 times
Been thanked: 126 times

Re: Texture changer with avatar sensor

Post 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?
These users thanked the author Christine Nyn for the post:
Michael Timeless
User avatar
Michael Timeless
Posts: 113
Joined: Thu Sep 24, 2015 5:13 am
Location: Crestwood, Illinois
Has thanked: 393 times
Been thanked: 153 times
Contact:

Re: Texture changer with avatar sensor

Post by Michael Timeless »

I guess I could take the grandkids or great grandkids. The "kids" are in their 30s
Post Reply