Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

follow on command

Myeia Boa
Registered User
Join date: 18 Jul 2008
Posts: 9
07-27-2008 15:22
Hi guys , i have a script that i can not get to work , part of it i made myself and part of it is based on similar scripts . it is ment to follow an Avi in range after the owner gives it a command. However when it is rezzed it just sits there and i cant see why?



float vecdist = llVecDist(llGetPos(),llDetectedPos(i));
for(i=0;i<n;i++)
integer targetID;
vector destination;
float range = 0.5;
string temp;
integer i;
default
{
state_entry()
{
llListen(2,"",llGetOwner(),"";);
}

listen(integer channel, string name,key id,string message)
{
temp=llGetSubString(message,0,6);
if(temp=="follow ";)
{
temp=llGetSubString(message,7,-1);
llSensor("",NULL_KEY,AGENT,96,PI*2);
}
else if (message == "reset";)
{
llResetScript();
}
else if(message == "stop follow";)
{
llTargetRemove(targetID);
llStopMoveToTarget();
}
}
sensor(integer n)
{
destination = llDetectedPos(i);
targetID = llTarget(destination, range);
float dif = 5;

{
vector detpos = llDetectedPos(i);
if(llSubStringIndex(llToLower(llDetectedName(i)),llToLower(temp))!=-1)
{
llMoveToTarget(<detpos.x -= 1,detpos.y,detpos.z>, 0.1);
llOwnerSay("follow " + llDetectedName(i));
}
}
}
listen(integer channel, string name,key id,string message)
{
if(message == "stop follow";)
llTargetRemove(targetID);
llStopMoveToTarget();
}
}


could anyone point me in the right direction , or tell me where to look , THnaks.
sorry if this is an imbeded script im not sure how to do that.
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
07-27-2008 17:22
as a start I found 3 errors:

1. What are the two first lines doing in the global variables domain?(outside default state)
The lines are:
From: someone
float vecdist = llVecDist(llGetPos(),llDetectedPos(i));
for(i=0;i<n;i++)

2.You can't have two two listen event handlers in one state
3.Variable: 'i' in the sensor event handler is not defined
...and there are probably more
Happy scripting:)
_____________________
From Studio Dora
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
07-27-2008 17:46
AGENT is a constant in LSL, limiting the sensor to avatars

and i is defined as a global, since its a null value it doesnt do anything but it is defined
Urrong Urnst
Registered User
Join date: 12 Jul 2008
Posts: 49
07-28-2008 01:23
I tried to fix your script. When looking in current script it looks like u wanted to follow an avatar that is defined by name. But with that for statement it looked like u wanted to follow from one avatar to another so i am not realy sure what u wanted :). I made the script that will follow an avatar defined by exact case sensitive name.

CODE

string avatar_name = "";
vector offset = <0, 1, 0>;

default
{

state_entry()
{
llSetStatus(STATUS_PHYSICS, TRUE);
llListen(2,"",llGetOwner(),"");
}

listen(integer channel, string name,key id,string message)
{
if(llGetSubString(message, 0, 6)=="follow ")
{
avatar_name = llGetSubString(message, 7, -1);
llSensorRepeat(avatar_name, "", AGENT, 96, PI, .1);
}
else if (message == "reset")
{
llResetScript();
}
else if(message == "stop follow")
{
llSensorRemove();
}
}

sensor(integer n)
{
vector detpos = llDetectedPos(0);
rotation rot = llDetectedRot(0);
llMoveToTarget(detpos + (offset * rot), .1);
}

no_sensor()
{
llOwnerSay("You misstyped the name or the agent is out of the sensor range!");
llSensorRemove();
}
}


Ok i fixed the errors and tested the script in world and it seems to work fine.
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
07-28-2008 03:35
Also remmember the object needs to be physical, this is not set in the script so it needs to be set by editing the object.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
07-28-2008 10:38
From: Urrong Urnst
I
Might be some syntax mistakes in it or i might miss something important :P sry for that. If it ont work post what compiler says or what is the objects behavior.


One of them, I think, is llSensorRepeat("avatar_name", "", AGENT, 96, PI, .1); Shouldn't that be
CODE
  llSensorRepeat(avatar_name,  "", AGENT, 96, PI, .1); 
without the quotes? Otherwise it'll be looking for someone by the name of "avatar_name" rather than for whatever that variable stands.
Urrong Urnst
Registered User
Join date: 12 Jul 2008
Posts: 49
07-28-2008 11:09
Yup u are right. I forgot that name is already a string :D. I'll fix that right away ty.