ainst Composer Posted January 25, 2019 Share Posted January 25, 2019 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 More sharing options...
Profaitchikenz Haiku Posted January 25, 2019 Share Posted January 25, 2019 (edited) 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 January 25, 2019 by Profaitchikenz Haiku 1 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 25, 2019 Share Posted January 25, 2019 (edited) 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 January 25, 2019 by Rolig Loon typo, of course 1 1 Link to comment Share on other sites More sharing options...
Profaitchikenz Haiku Posted January 25, 2019 Share Posted January 25, 2019 Beat you to it this time, Rolig 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 25, 2019 Share Posted January 25, 2019 Just now, Profaitchikenz Haiku said: Beat you to it this time, Rolig Heh. I like it. Now he has at least two ways to get started. 😎 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted January 26, 2019 Author Share Posted January 26, 2019 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 More sharing options...
Rolig Loon Posted January 26, 2019 Share Posted January 26, 2019 20 minutes ago, ainst Composer said: will be difficult to make the name of an avatar come instead of a word ALERT? That's what mine does. 🙄 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted January 26, 2019 Author Share Posted January 26, 2019 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 More sharing options...
steph Arnott Posted January 26, 2019 Share Posted January 26, 2019 (edited) 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 January 26, 2019 by steph Arnott 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted January 26, 2019 Author Share Posted January 26, 2019 (edited) 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 January 26, 2019 by ainst Composer Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 26, 2019 Share Posted January 26, 2019 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. 1 Link to comment Share on other sites More sharing options...
steph Arnott Posted January 26, 2019 Share Posted January 26, 2019 1 minute ago, ainst Composer said: Wow! Thanks a lot! Works now! What to do with llListSort? It will rearrange the list entries into a logical order. The script runs more efficiently. http://wiki.secondlife.com/wiki/LlListSort 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted January 26, 2019 Author Share Posted January 26, 2019 @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 More sharing options...
Rolig Loon Posted January 26, 2019 Share Posted January 26, 2019 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. 🙂 1 Link to comment Share on other sites More sharing options...
steph Arnott Posted January 26, 2019 Share Posted January 26, 2019 (edited) 8 minutes ago, ainst Composer said: @Profaitchikenz Haiku @Rolig Loon Foget that, i miss read. Edited January 26, 2019 by steph Arnott 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted January 26, 2019 Author Share Posted January 26, 2019 (edited) 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 January 26, 2019 by ainst Composer Link to comment Share on other sites More sharing options...
steph Arnott Posted January 26, 2019 Share Posted January 26, 2019 (edited) 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 January 26, 2019 by steph Arnott 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 26, 2019 Share Posted January 26, 2019 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. 1 Link to comment Share on other sites More sharing options...
steph Arnott Posted January 26, 2019 Share Posted January 26, 2019 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. 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted January 26, 2019 Author Share Posted January 26, 2019 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 More sharing options...
steph Arnott Posted January 26, 2019 Share Posted January 26, 2019 (edited) 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 January 26, 2019 by steph Arnott 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 26, 2019 Share Posted January 26, 2019 3 minutes ago, ainst Composer said: I am afraid to ask how to make the greeting message be heard only by the visitor and not all around? That's what llRegionSayTo does. 1 Link to comment Share on other sites More sharing options...
ainst Composer Posted January 26, 2019 Author Share Posted January 26, 2019 14 minutes ago, steph Arnott said: 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. oh so sorry i confused you! in this case i mean chat message. Link to comment Share on other sites More sharing options...
steph Arnott Posted January 26, 2019 Share Posted January 26, 2019 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!"); } } 1 Link to comment Share on other sites More sharing options...
Kyrah Abattoir Posted January 27, 2019 Share Posted January 27, 2019 (edited) 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 January 27, 2019 by Kyrah Abattoir Link to comment Share on other sites More sharing options...
Recommended Posts
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