Jump to content

LSL_Help_Post_7


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

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

Recommended Posts

Questions:

1. Is there any code to reset only the script the code is in?

2. This script cannot receive message from another script, why?

integer schannel = 489;  
 
float DELAY = 0.5;   // Seconds between blinks; lower for more lag
float RANGE = 3.0;   // Meters away that we stop walking towards
float TAU = 1.0;     // Make smaller for more rushed following
 
// Avatar Follower script, by Dale Innis
// Do with this what you will, no rights reserved
// See https://wiki.secondlife.com/wiki/AvatarFollower for instructions and notes
 
float LIMIT = 60.0;   // Approximate limit (lower bound) of llMoveToTarget
 
integer lh = 0;
integer tid = 0;
string targetName = "";
key targetKey = NULL_KEY;
integer announced = FALSE;
stopFollowing() {
  llTargetRemove(tid);  
  llStopMoveToTarget();
  llSetTimerEvent(0.0);
  llOwnerSay("No longer following.");
}
 
startFollowingName(string name) {
  targetName = name;
  llSensor(targetName,NULL_KEY,AGENT_BY_LEGACY_NAME,96.0,PI);  // This is just to get the key
}
 
startFollowingKey(key id) {
  targetKey = id;
  llOwnerSay("Now following "+targetName);
  keepFollowing();
  llSetTimerEvent(DELAY);
}
 
keepFollowing() {
  llTargetRemove(tid);  
  llStopMoveToTarget();
  list answer = llGetObjectDetails(targetKey,[OBJECT_POS]);
  if (llGetListLength(answer)==0) {
    if (!announced) llOwnerSay(targetName+" seems to be out of range.  Waiting for return...");
    announced = TRUE;
  } else {
    announced = FALSE;
    vector targetPos = llList2Vector(answer,0);
    float dist = llVecDist(targetPos,llGetPos());
    if (dist>RANGE) {
      tid = llTarget(targetPos,RANGE);
      if (dist>LIMIT) {
          targetPos = llGetPos() + LIMIT * llVecNorm( targetPos - llGetPos() ) ; 
      }
      llMoveToTarget(targetPos,TAU);
    }
  }
}
 
default {
 on_rez(integer x) {
    llResetScript();   // Why not?
  }
 
  link_message(integer sender_num, integer num, string msg, key id) {
    if (num==1) {
        if (msg == "Off") {
      stopFollowing();
    } else {
      startFollowingName(msg);
    }
    }
  }
 
  no_sensor() {
    llOwnerSay("Did not find anyone named "+targetName);
  }
 
  sensor(integer n) {
    startFollowingKey(llDetectedKey(0));  // Can't have two ppl with the same name, so n will be one.  Promise. :)
  }
 
  timer() {
    keepFollowing();
  }
 
  at_target(integer tnum,vector tpos,vector ourpos) {
    llTargetRemove(tnum);
    llStopMoveToTarget();  
  }
 
}

Link to comment
Share on other sites

7 minutes ago, childhoodbestfriend489 said:

1. Is there any code to reset only the script the code is in?

2. This script cannot receive message from another script, why?

  1. llResetScript will cause the script to reset itself.
    llResetOtherScript will reset a script in the current prim with a specific name.
     
  2. It can. How are you sending messages to it?
Edited by Wulfie Reanimator
  • Like 1
Link to comment
Share on other sites

I tested and found that sender can send correct information.

 

Sender script :

integer schannel = 489;
string dmsg = "Choose the name of person to magically follow:";
list button =["Off"];
default
{
  touch_start(integer total_number)
    {
       llSensor("",NULL_KEY,AGENT,100,PI);
       llSetTimerEvent(30);
       
    }
    sensor(integer peeps)
    {
        while(peeps--)
        {
            button += llKey2Name(llDetectedKey(peeps));
        }
        llDialog(llGetOwner(),dmsg,button,schannel);
        llListen(schannel,"",llGetOwner(),"");
    }
    no_sensor()
    {
        llRegionSayTo(llGetOwner(),0,"No avatar in range, please move closer.");
    }
    listen(integer channel, string name, key id, string cmd)
    {
        llMessageLinked(LINK_THIS, 1, cmd, "");
        llResetScript();
    }
    timer()
    {
        llRegionSayTo(llGetOwner(),0,"Dialog menu timeout.");
    }
}

 

Edited by childhoodbestfriend489
Link to comment
Share on other sites

Ok, so if you still don't think the receiving script is hearing link messages, do this

 

in the sending script, just inside the listen event before it sends the link message, add

llOwnerSay(""Will send >" + cmd + "<");

 

And in the receiving script, just inside the link_message event, before you test num, add this

llOwnerSay("Heard sender " + (string) sender_num + " send number " + (string) num + " saying >" + msg + "<");

 

Notice how I've wrapped the actual messages inside chevrons so that if a blank message gets sent it's going to be obvious like this ><

 

Link to comment
Share on other sites

1 minute ago, childhoodbestfriend489 said:

Can buttons' text character be counted?

Characters can be counted with llStringLength.

12 minutes ago, childhoodbestfriend489 said:

Here, this is used. Can't while(peeps<13) be used? and does that mean loop less than 13 times?

sensor(integer peeps)
    {
        while(peeps--)
        {
            button += llKey2Name(llDetectedKey(peeps));
        }

"while (peeps < 13)" would most likely cause a very long loop.

Instead, you should set peeps to 12 if peeps is greater than 12. That way the loop doesn't need to be edited and you'll never include more than the 12 closest people.

Link to comment
Share on other sites

24 minutes ago, childhoodbestfriend489 said:

Can buttons' text character be counted?

There's a potential pitfall to be aware of here if you're using display names. Button text is limited to 24 bytes. llStringLength returns the number of characters. Display names often contain multi-byte characters.

There's a code snippet in the llDialog wiki page that shows you how to truncate a string that may include multi-byte characters here: http://wiki.secondlife.com/wiki/LlDialog#buttons_limits, and, for good measure, one that shows you how to check the byte length of a string here: http://wiki.secondlife.com/wiki/LlStringToBase64#Examples.

  • Like 2
Link to comment
Share on other sites

According to the wiki, the maximum distance llSensor detects things at is the 4th parameter you give it, up to a limit of 96.0 : http://wiki.secondlife.com/wiki/LlSensor llDialog() however has a more or less 'infinite' range when used in the usual way (don't quote me on that, I've not tested it across region borders and corners yet), and llRegionSayTo() is limited to the current region. FWIW you can replace llRegionSayTo(llGetOwner(),0,"Dialog menu timeout."); with llOwnerSay("Dialog menu timeout."); to improve its range.

Link to comment
Share on other sites

43 minutes ago, Quistessa said:

lDialog() however has a more or less 'infinite' range

'fraid not, it uses chat and so is subject to the usual 20 metres range limit. The dialog buttons stay visible until clicked, but if the toucher or the listening prim have moved away beyond the 20m range, the response won't get heard by the listener.

 

llOwnerSay has an almost infinite range, though, it's effectively an IM call without the long delay/

Link to comment
Share on other sites

I've just been testing this. In the "Normal scenario" where the listening object and the object sending the dialog are one and the same, the response will go through as long as the object is rendered in the dialogee's viewer. the toucher can be 3 or four sims away, and the response will still be heard, because the response comes from the object sending the dialog.

Try this, make a simple object with a script like so:

default
{
    state_entry()
    {
        llSetTimerEvent(10.0);
    }

    timer()
    {
        llDialog(llGetOwner(),"This is a Test",["OK"],0);
    }
}

and rez it. whenever you press "OK" anyone within 20m of the object will hear you say "OK". even if you're a few sims away.

Link to comment
Share on other sites

35 minutes ago, Profaitchikenz Haiku said:

'fraid not, it uses chat and so is subject to the usual 20 metres range limit. The dialog buttons stay visible until clicked, but if the toucher or the listening prim have moved away beyond the 20m range, the response won't get heard by the listener.

Not true. Well, kind of true. It's the only exception to normal chat behavior I know of.

The dialog button is spoken by the touching avatar, but the origin of the message is at the location of the script that called llDialog.

The distinction is that you can operate a dialog from an infinite distance, and any object that is within 20 meters of the dialog (not the avatar) will get the message.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1272 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...