Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Goto script? Need help.

Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-18-2006 15:35
I'm making a "goto agent" script, and this script just wont work. It compiles, and the ownersay function takes place, but it just won't move. What's wrong? Once again, thanks alot.
CODE
string target;
default {
state_entry() {
llListen(2, "", llGetOwner(), "");
}
listen(integer channel, string name, key id, string message) {
if (llGetSubString(llToLower(message), 0, 4) == "goto ") {
target = llGetSubString(llToLower(message), 5, -1);
llSensor("", NULL_KEY, AGENT, 96, TWO_PI);
}
}
sensor(integer num_detected){

llMoveToTarget(llDetectedPos(0),2);
}


collision(integer num_detected){
llOwnerSay("Goto has stopped, you have collided with something.");
llStopMoveToTarget();
}

state_entry(){
if(llDetectedKey(0) == llGetOwner()){
llStopMoveToTarget();
}
}
}
Kayla Stonecutter
Scripting Oncalupen
Join date: 9 Sep 2005
Posts: 224
03-18-2006 16:28
llMoveToTarget() only works on physical objects. You'll either need to use llSetPos() in a loop since it only moves up to 10m at a time, or set the object to physical just before moving with llSetStatus(STATUS_PHYSICS, TRUE); , then set to FALSE when stopping.
_____________________
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
03-18-2006 17:39
If that's being used in an attachment, there's a little bug you'e run into.

Compile your script, then detach the object. Wait a moment, re-attach and use the script - it will work then. This seems to effect llMoveToTarget, llSetForce and llApplyImpulse at least.
_____________________
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-18-2006 18:06
Okay, I'll try out both suggestions as soon as possible :D Thanks again!
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-19-2006 04:21
Hmm, I tried both suggestions and none work. I think the Agent command just isn't working now... It detects the person closest to me rather then the person I said in the command. What is wrong?
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
03-19-2006 07:09
Your sensor call is wrong...

Your line currently reads llSensor("", NULL_KEY, AGENT, 96, TWO_PI);

It should read llSensor(target, NULL_KEY, AGENT, 96, PI);

The line you've got finds all the agents, and the sensor event then correctly goes to the closest (llDetectedKey(0)). I think the llToLower() part will also break it, I'm pretty sure llSensor case matches names - so eloise pastuer is different to Eloise Pasteur.

The TWO_PI, PI thing at the end - the wiki actually explains it nicely, but basically the angle defines the spread of a cone across one axis (so an angle of PI gives you PI/2 on either side of the objects x axis I think) - the cone then sweeps around the z-axis, so PI will give you a full spherical sweep.
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-19-2006 14:18
I had read that TWO_PI = 360º sweep? And also, the goto script will still not work correctly. Is the problem possibly that I have the script inside a HUD attachment?
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
03-19-2006 14:21
From: Exile Loudon
I had read that TWO_PI = 360º sweep? And also, the goto script will still not work correctly. Is the problem possibly that I have the script inside a HUD attachment?
As above - you need to compile (save), detach, and re-attach to have most force-application calls work in an attachment.
_____________________
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
03-19-2006 15:49
Try http://secondlife.com/badgeo/wakka.php?wakka=llSensor and scroll down to the detection cone section. Whatever else you may have read is wrong, or misunderstood - the wiki says it works as I tried (rather more briefly) to explain - and every test of sensor's I've ever done says that it works the way the wiki says.
Nexus Nash
Undercover Linden
Join date: 18 Dec 2002
Posts: 1,084
03-19-2006 19:05
It's PI. Edit from TWO_PI, my bad I was nose full in trig and never realized sensor was only PI. However upon some testing and explanations, you can't really use it to break down quadrants, it's more like taking a sphere and using the dimple.
llToLower breaks it.
Use at_target and not_at_target events. It's better scripting practice when moving like this. Read up on wiki on these events.
_____________________
Kayla Stonecutter
Scripting Oncalupen
Join date: 9 Sep 2005
Posts: 224
03-20-2006 11:52
While TWO_PI does equal 360º most of the time, in a sensor event the angle is basically doubled, which means PI gives you a full sphere scan, as Eloise has tried to say twice now. I make a HUD radar, use PI in the sensor, and it detects avatars all around me.

As for the targeting issue, putting a name in the llSensor call only matches exactly, including capitals. If you want to be able to type only part of the name in, try this:
CODE
sensor(integer num)
{
integer s;
for(s = 0; s < num; ++s)
{
string detectname = llToLower(llDetectedName(s));
if(llSubStringIndex(detectname, targetname) == 0)
{
//Movement code here
return;
}
}
}
_____________________
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-21-2006 00:05
How would this be impplemented into my script? (Sorry; I'm totally useless when it comes to lists & strings.)
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-22-2006 14:12
*bump*