Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Please Tell Me How

BioMolecular Chemistry
Registered User
Join date: 16 Apr 2008
Posts: 24
10-04-2008 17:09
Hello here is a snippet of code I'm working on. I'm trying to get it so that when the object I put it in moves to the target avie there is a llSay call. I only want the call to come when the object has finished moving though and sitting above the target and not before. I can't get it for the life of me and it's doing my head in. Please Help :)?

integer stalkernum = 0;
key targetKey = NULL_KEY;

default
{
link_message(integer sender_num, integer num, string str, key id)
{
if(str == "MSGStartFollowing" && stalkernum == num)
{
targetKey = id;
llSensorRepeat("", targetKey, AGENT, 96, PI, 0.1);
}
else if(str == "MSGStopFollowing";)
{
llSensorRemove();
targetKey = NULL_KEY;
}
else if(str == "MSGTargetNotFound";)
{
llSensorRemove();
targetKey = NULL_KEY;
}
}

on_rez(integer start_param)
{
llResetScript();
}

no_sensor()
{
llSensorRemove();
llMessageLinked(LINK_THIS, 0, "MSGTargetNotFound", targetKey);
targetKey = NULL_KEY;
}

sensor(integer num_detected)
{
vector desiredposition = llDetectedPos(0) + <0,0,2.935>;
vector currentposition = llGetPos();
currentposition = llGetPos();
llSetPos(desiredposition);
}
}
Shifting Dreamscape
Always questioning ...
Join date: 12 Dec 2007
Posts: 266
10-05-2008 00:09
Have you tried the moving_end event? http://wiki.secondlife.com/wiki/Moving_end

And alternately have your considered using the llTarget function in conjunction with the at_target event?

http://wiki.secondlife.com/wiki/LlTarget
http://wiki.secondlife.com/wiki/At_target
BioMolecular Chemistry
Registered User
Join date: 16 Apr 2008
Posts: 24
Thanks Shifting
10-05-2008 01:02
I'm trying to use the llTarget function in conjunction with the at_target event but it's not working. See below.

integer target_id;
integer stalkernum = 0;
key targetKey = NULL_KEY;
vector target_pos;

default
{
link_message(integer sender_num, integer num, string str, key id)
{
if(str == "MSGStartFollowing" && stalkernum == num)
{
targetKey = id;
llSensorRepeat("", targetKey, AGENT, 96, PI, 0.1);
}
else if(str == "MSGStopFollowing";)
{
llSensorRemove();
targetKey = NULL_KEY;
}
else if(str == "MSGTargetNotFound";)
{
llSensorRemove();
targetKey = NULL_KEY;
}
}

at_target(integer tnum, vector targetpos, vector ourpos)
{
if (tnum == target_id)
{
llSay(-999, "hello there";);
}
}

state_entry()
{
}

on_rez(integer start_param)
{
llResetScript();
}

no_sensor()
{
llSensorRemove();
llMessageLinked(LINK_THIS, 0, "MSGTargetNotFound", targetKey);
targetKey = NULL_KEY;
}

sensor(integer num_detected)
{
vector desiredposition = llDetectedPos(0) + <0,0,2.935>;
vector currentposition = llGetPos();
currentposition = llGetPos();
llSetPos(desiredposition);
target_pos = desiredposition;
target_id = llTarget(target_pos, 0.5);
}
}
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
10-05-2008 01:15
What is it doing (or not doing) so far? Is the object moving? Is it doing the llSay too early or late?


A couple of things I do notice: you're scanning in a radius of 96m, but using llSetPos to jump directly to the location. llSetPos only works up to 10m, and will silently fail if you try to go further. You basically need to break the journey down into 10m chunks (do that by getting a vector from your object to the target, divide it by its own magnitude, and multiply it by 10).

Other thing I notice is that your object does "llSay" on channel -999. Only channel 0 is normally visible to avatars, so do you have some other device listening on -999 to relay the message?
Shifting Dreamscape
Always questioning ...
Join date: 12 Dec 2007
Posts: 266
10-05-2008 03:57
I think the reson your not getting the at_target event (though I could be wrong) is because your setting the target AFTER you have positioned the object.

and the comment Pedro made in regards to llSetPos could be the issue as well if the object is never reaching .. or the llSay channel issue ...
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
10-05-2008 10:47
Why aren't you just adding the logic to your sensor event? For example:

CODE

sensor(integer num_detected)
{
vector desiredposition = llDetectedPos(0) + <0,0,2.935>;

vector currentposition = llGetPos();
if (llVecDist(currentposition, desiredposition) < 10.0)
{
// This llSetPos() will get us there
llSetPos(desiredposition);
llSay(...);
} else
{
llSetPos(desiredposition);
}
}
BioMolecular Chemistry
Registered User
Join date: 16 Apr 2008
Posts: 24
thanks people
10-12-2008 04:49
thx guys that works :)