Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Come to Me Script

October7th Aquacade
Registered User
Join date: 5 Nov 2006
Posts: 3
11-09-2006 06:06
So I'm new at scripting, but I read the crash course and part of the tutorial. I also took 101-104 at TUI -- so I'm trying. I tried to write that makes an object come back to its owner on command.

The script isn't working right -- it just makes the object go in a random direction. I think the problem is with the vector avpos. I read that in this forum that llGetDetectedPos(0) returns a vector of your avatar's position, but I'm not sure it's working. Any suggestions?

October7th

------------------------------------------

vector startposition;

default
{
state_entry()
{
//Confirm readiness, calculate start position of object

llListen( 0, "", llGetOwner(), "";);
llSay(0, "Ready.";);
startposition = llGetPos();
}

//listen to command

listen( integer channel, string name, key id, string message )
{

//comehere command sends to comehere state

if (message == "come here";)
{
state comehere;
}

}
}

state comehere
{
state_entry()
{

//confirm state change

llSay (0, "Coming.";);

//get my avatar position

vector avpos;
avpos = llDetectedPos(0);

//create random offest of space

float x_distance = llFrand(1.0);
float y_distance = llFrand(1.0);
float z_distance = llFrand(1.0);

//move object to my avatar position with a slight offset

vector increment = <x_distance, y_distance, 0.0>;
vector newposition = avpos + increment;
llSetPos (newposition);

//back to start

llResetScript();
}
}
Dillon Morenz
Registered User
Join date: 21 May 2006
Posts: 85
11-09-2006 07:05
llDetectedPos() is not returning the avatar's position. You need to scan for the position of the named avatar (their name is provided in the listen() event of course) with llSensor() instead.
_____________________
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
Also...
11-09-2006 13:30
If your object is small, it will end up floating near its owner's middle, I think. After you do the llSetPos(), you might need to lower down to the ground.
October7th Aquacade
Registered User
Join date: 5 Nov 2006
Posts: 3
Thank you
11-12-2006 12:19
Thanks,

the suggestions worked!
Linus Pualhan
Registered User
Join date: 18 Nov 2006
Posts: 1
Come Here Script
11-18-2006 23:45
Hey, could you post the final code that worked?

Thanks!
Nynthan Folsom
Registered User
Join date: 29 Aug 2006
Posts: 70
12-02-2006 00:41
The reason the llDetectedPos didn't work is that it only works in certain events.

From: lslwiki
The llDetected* functions will only return a meaningful value in the collision(), collision_start(), collision_end, sensor, touch, touch_start, or touch_end events.