Jump to content

ainst Composer
 Share

You are about to reply to a thread that has been inactive for 1914 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello! I am trying to create a script with something like an alarm that sends me a message when someone comes to visit me in my absence. I managed to write something but its not ok.
It sends messages all the time while person in range, and I only need one time alert. and at the same time, if a person leaves the range and comes back, the alarm must be triggered again.
how to do it?

That's what i managed to write so far

float range = 10.0; // in meters
float rate = 10.0; // in seconds


default
{
    state_entry()
    {
        llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
    }

    sensor( integer number_detected )
    {
        llInstantMessage( llGetOwner(), "ALERT!" );
    }
}

 

Link to comment
Share on other sites

As a starter, add three things:

 

a global variable

integer alerted = 0;

a no_sensor event 

no_sensor()
{
	alerted = 0;
}

 

and inside the sensor event, modify it so that it only alerts you if alerted is 0, and then sets alerted to 1;

sensor(integer num_found)
{
	if( !alerted)
	{
		// send IM or ping the console bell
		alerted = 1;	// stop further alerts until no_sensor turns this back off
	}
}

 

You can later refine this by keeping track of who it has detected and raising an alert when a new person arrives.

Alternatively, keep track of num_found in a global variable and raise an alert each time num_found is greater than the last saved value

 

Edited by Profaitchikenz Haiku
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Be prepared to pull the plug on this thing when you get too many annoying messages.  This is the sort of script that sounds good until you actually launch it.

Anyway ....  all you need to do is save the name of your visitor in a global list and then check that list every time the sensor is triggered.  If the person isn't already on the list, send the IM and add the person to the list.  If he is there, do nothing.  And then, if there's nobody there at all, wipe the list clean.  It's probably a good idea to tell the script to ignore you, and maybe a few whitelisted friends.

So, something generically like this (assuming that you have created lAllAvs and have a repeating sensor going...)

sensor ( integer num)
{
    integer i;
    while ( i < num )
    {
        if ( !~llListFindList( lAllAvs, [ llDetectedName(i) ] ) )
        {
            lAllAvs += [ llDetectedName(i) ];
            llInstantMessage( llGetOwner(), "ALERT!  " + llDetectedName(i) + " is visiting." );
        }
        ++i;
    }
}

no_sensor()
{
    lAllAvs = [];
}

 

Edited by Rolig Loon
typo, of course
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

52 minutes ago, Rolig Loon said:

Heh.   I like it.  Now he has at least two ways to get started.  😎

 

53 minutes ago, Profaitchikenz Haiku said:

Beat you to it this time, Rolig :)

 

Hello! thanks very much for answers!

just one more question. will be difficult to make the name of an avatar come instead of a word ALERT?

Link to comment
Share on other sites

12 hours ago, Rolig Loon said:

That's what mine does. 🙄

Thank you more times! Here's what I got. but it gives an error. What have I done wrong? It says: Function call mismatches type or number of arguments.

float range = 10.0; // in meters
float rate = 1.0; // in seconds
integer lAllAvs;

default
{
    state_entry()
    {
        llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
    }



sensor ( integer num)
{
    integer i;
    while ( i < num )
    {
        if ( !~llListFindList( lAllAvs, [ llDetectedName(i) ] ) )
        {
            lAllAvs += [ llDetectedName(i) ];
            llInstantMessage( llGetOwner(), "ALERT!  " + llDetectedName(i) + " is visiting." );
        }
        ++i; 
    }
}

no_sensor()
{
    lAllAvs = [];
}
}

 

Link to comment
Share on other sites

59 minutes ago, ainst Composer said:

Thank you more times! Here's what I got. but it gives an error. What have I done wrong? It says: Function call mismatches type or number of arguments.


float range = 10.0; // in meters
float rate = 1.0; // in seconds
//integer lAllAvs;//this is incorrect  it should be 
list lAllAvs;

default
{
    state_entry()
    {
        llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
    }



sensor ( integer num)
{
    integer i;
    while ( i < num )
    {
        if ( !~llListFindList( lAllAvs, [ llDetectedName(i) ] ) )
        {
            lAllAvs += [ llDetectedName(i) ];
            llInstantMessage( llGetOwner(), "ALERT!  " + llDetectedName(i) + " is visiting." );
        }
        ++i; 
    }
}

no_sensor()
{
    lAllAvs = [];
}
}

 

I also noticed that the script untill no sensor is allways adding new avs to the list. Is that what you intended because the list could end up with a lot of redundant information. I my self would use a 

llListSort

function as well.

Edited by steph Arnott
  • Thanks 1
Link to comment
Share on other sites

47 minutes ago, steph Arnott said:

I also noticed that the script untill no sensor is allways adding new avs to the list. Is that what you intended because the list could end up with a lot of redundant information. I my self would use a 


llListSort

function as well.

Wow! Thanks a lot! Works now!

What to do with llListSort? Just replace llListFindList with it?

Edited by ainst Composer
Link to comment
Share on other sites

1 hour ago, ainst Composer said:

Thank you more times! Here's what I got. but it gives an error. What have I done wrong? It says: Function call mismatches type or number of arguments.


float range = 10.0; // in meters
float rate = 1.0; // in seconds
list lAllAvs;    // This is a LIST.  You had it declared as an INTEGER

default
{
    state_entry()
    {
        llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
    }



    sensor ( integer num)
    {
        integer i;
        while ( i < num )
        {
            if ( !~llListFindList( lAllAvs, [ llDetectedName(i) ] ) )
            {
                lAllAvs += [ llDetectedName(i) ];
                llInstantMessage( llGetOwner(), "ALERT!  " + llDetectedName(i) + " is visiting." );
            }
           ++i; 
        }
    }

    no_sensor()
    {
        lAllAvs = [];
    }
}

 

When you see an error message, always notice exactly what it says and exactly where the cursor is.  That will give you the best clues about where you made a mistake. The error messages in the in-world LSL editor are sometimes cryptic, but a script as small as this is very easy to debug.  There aren't many places to go wrong, after all.  As you start writing longer, more complicated scripts, you should start thinking about using an external editor that gives you more helpful error messages.  You should also get in the habit of being very neat, to improve readability.  Indentation and the logical use of white space mean nothing to the computer but are vital for humans.

Steph is also right that as time goes on you will find many ways to add flourishes and extra features to your scripts.  This one is very bare-bones, so there are many things you can do to make it more versatile.  I wouldn't worry much about her comment that the script keeps adding more names while people are around, for two reasons: (1) it will only add each person's name once, no matter how long the person stays within range,  and (2) the entire list will clear as soon as everyone leaves. If you are going to be using this script in a very busy area, however, give her comment some thought.  It will take a long time to fill up this script and make it stall, but it could happen.

  • Thanks 1
Link to comment
Share on other sites

@Profaitchikenz Haiku @Rolig Loon @steph Arnott

Thanks to you all very much!

I also made this script called it a "welcome door carpet". triggered when the visitor collides it. maybe someone will find it useful. As can be seen from the script, it welcomes the visitor, plays the sound and sends the owner a message about the arrival. Also if you have any suggestions about improvement  greatly appreciated!

//string sound = "ed124764-705d-d497-167a-182cd9fa2e6c"; 

default
{
    collision_start(integer num)
    
    {
        integer i;
        llInstantMessage( llGetOwner(), "ALERT!  " + llDetectedName(i) + " is visiting." );
        llSay (0, "Welcome!");
        llPlaySound  ("YOUR_SOUND", 1.0);

        //llTriggerSound(sound, 1.0);
    }
}

 

Link to comment
Share on other sites

Congratulations.  This new script is even simpler.  I suspect that you will soon find that it is just as annoying as the first one.  You will wish that you had never decided to have it send you IMs. Still, both scripts are fun learning exercises and you have done well. 🙂

  • Thanks 1
Link to comment
Share on other sites

13 minutes ago, steph Arnott said:

If you use GetOwner it will message only the owner and not the agent you intend.

Thanks very much!

Where should it be located? and will the visitor hear the greeting?

    {
        key owner = llGetOwner();
        llInstantMessage(owner, "Welcome!");
    }

I want the carpet to greet them. maybe not in local chat.

I am confused........

Edited by ainst Composer
Link to comment
Share on other sites

7 minutes ago, ainst Composer said:

Thanks very much!

Where should it be located? and will the visitor hear the greeting?


    {
        key owner = llGetOwner();
        llInstantMessage(owner, "Welcome!");
    }

I want the carpet to greet them. maybe not in local chat.

Use the collision event to get their key. Then use that to target the av. BTW there is a 2.0 second pause before the next you need to be aware of.

Edited by steph Arnott
  • Thanks 1
Link to comment
Share on other sites

Don't bother with llInstantMessage for this application, if you are sending a message to the person who stepped on the carpet.  llInstantMessage is really best for sending messages to people in other regions and, as Steph points out, it has a slight delay, which can be annoying.  It's fine for sending the "ALERT!" message to yourself, but use llRegionSayTo for talking to the visitor.

  • Thanks 1
Link to comment
Share on other sites

1 minute ago, Rolig Loon said:

Don't bother with llInstantMessage for this application, if you are sending a message to the person who stepped on the carpet.  llInstantMessage is really best for sending messages to people in other regions and, as Steph points out, it has a slight delay, which can be annoying.  It's fine for sending the "ALERT!" message to yourself, but use llRegionSayTo for talking to the visitor.

I forgot the regionsay function.

  • Thanks 1
Link to comment
Share on other sites

25 minutes ago, Rolig Loon said:

Don't bother with llInstantMessage for this application, if you are sending a message to the person who stepped on the carpet.  llInstantMessage is really best for sending messages to people in other regions and, as Steph points out, it has a slight delay, which can be annoying.  It's fine for sending the "ALERT!" message to yourself, but use llRegionSayTo for talking to the visitor.

 

23 minutes ago, steph Arnott said:

I forgot the regionsay function.

You have already helped me so much that I am afraid to ask how to make the greeting message be heard only by the visitor and not all around?

Link to comment
Share on other sites

4 minutes ago, ainst Composer said:

 

You have already helped me so much that I am afraid to ask how to make the greeting message be heard only by the visitor and not all around?

You can use this, it will cap the sound range  http://wiki.secondlife.com/wiki/LlTriggerSoundLimited 

I keep reading 'heard' and think you mean sound.

Edited by steph Arnott
  • Thanks 1
Link to comment
Share on other sites

1 minute ago, ainst Composer said:

oh so sorry i confused you!

in this case i mean chat message.

default
{
    state_entry()
    {
        //
    }
    collision_start(integer total_number)
    {    
        llRegionSayTo(llDetectedKey(0), 0, "Your shoes are filthy!");
    }
}

  • Thanks 1
Link to comment
Share on other sites

On 1/26/2019 at 4:05 PM, steph Arnott said:

It will rearrange the list entries into a logical order. The script runs more efficiently. http://wiki.secondlife.com/wiki/LlListSort

I don't see how anything is going to run more efficiently if you where to sort keys. Sorting a list is slow.

if ( !~llListFindList( lAllAvs, [ llDetectedName(i) ] ) )

Is already guarding against duplicate insertion.

Edited by Kyrah Abattoir
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1914 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...