Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

movement with llMoveToTarget

Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
01-02-2008 18:16
im making a hud with the ability to have the owner do a /10 # to define a distance they wont to move at, in theroy to me this should work, i put it into a string and it dosent seam to wont to work, this is the script that is in the main prim, the other scripts are just simple touch_start / linked message commands i cant seam to figure out what is wrong it is geting to main script just isnt recording the distace that the owner defines >.>


CODE

string d = "";
integer targetID;

default
{
state_entry()
{
llListen(10,"",llGetOwner(),"");
llOwnerSay("...Reset");
}
listen( integer channel, string name, key id, string message )
{
if (message == "reset")
{
llOwnerSay("Resetting HUD...");
llStopMoveToTarget();
llResetScript();
}
else
{
message == d;
llOwnerSay("Distance set to "+d);
}
}
link_message(integer sender_num, integer num, string msg, key id)
{
if(msg == "left")
{
llOwnerSay("LEFT");
vector destination = llGetPos() + <(integer)d, 0, 0>*llGetRot();
float range = 0.1;
targetID = llTarget( destination, range );
llMoveToTarget( destination, .2 );
}
if(msg == "right")
{
llOwnerSay("RIGHT");
vector destination = llGetPos() + <-(integer)d, 0, 0>*llGetRot();
float range = 0.1;
targetID = llTarget( destination, range );
llMoveToTarget( destination, .2 );
}
if(msg == "up")
{
llOwnerSay("UP");
vector destination = llGetPos() + <0, 0, (integer)d>*llGetRot();
float range = 0.1;
targetID = llTarget( destination, range );
llMoveToTarget( destination, .2 );
}
if(msg == "down")
{
llOwnerSay("DOWN");
vector destination = llGetPos() + <0, 0,-(integer)d>*llGetRot();
float range = 0.1;
targetID = llTarget( destination, range );
llMoveToTarget( destination, .2 );
}
if(msg == "fwd")
{
llOwnerSay("FWD");
vector destination = llGetPos() + <0,(integer)d,0>*llGetRot();
float range = 0.1;
targetID = llTarget( destination, range );
llMoveToTarget( destination, .2 );
}
if(msg == "back")
{
llOwnerSay("BACK");
vector destination = llGetPos() + <0,-(integer)d,0>*llGetRot();
float range = 0.1;
targetID = llTarget( destination, range );
llMoveToTarget( destination, .2 );
}
}
at_target( integer number, vector targetpos, vector ourpos )
{
llTargetRemove(targetID);
llStopMoveToTarget();
}
}
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
01-03-2008 09:09
else
{
message == d;
llOwnerSay("Distance set to "+d);
}


This is wrong. message == d; will test to see if message and d are equal, and retrn an unused value of TRUE or FALSE. YOu problably ment

d = message;

which will set d to the same value that message has.
_____________________
So many monkeys, so little Shakespeare.
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
01-03-2008 09:43
/me points at Lee and nods..

You can also simplify that script a bit, Mrc. Maybe something like this...
CODE
float d;
integer targetID;

DoMove (vector dir)
{
vector destination = llGetPos() + dir * llGetRot();
float range = 0.1;
targetID = llTarget( destination, range );
llMoveToTarget( destination, .2 );
}

default
{
state_entry()
{
llListen(10,"",llGetOwner(),"");
llOwnerSay("...Reset");
}

listen( integer channel, string name, key id, string message )
{
if (message == "reset")
{
llOwnerSay("Resetting HUD...");
llStopMoveToTarget();
llResetScript();
}
else
{
d = (float)message;
llOwnerSay("Distance set to " + (string)d);
}
}

link_message(integer sender_num, integer num, string msg, key id)
{
llOwnerSay(msg);

if (msg == "left")
{
DoMove (<d, 0.0, 0.0>);
}
else if (msg == "right")
{
DoMove (<-d, 0.0, 0.0>);
}
else if (msg == "up")
{
DoMove (<0.0, 0.0, d>);
}
else if (msg == "down")
{
DoMove (<0.0, 0.0, -d>);
}
else if (msg == "fwd")
{
DoMove (<0.0, d, 0.0>);
}
else if(msg == "back")
{
DoMove (<0.0, -d, 0.0>);
}
else
{
llOwnerSay ("Bogus message!");
}
}

at_target( integer number, vector targetpos, vector ourpos )
{
llTargetRemove(targetID);
llStopMoveToTarget();
}
}
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-03-2008 09:54
This is posted more for doubtful scripting humour value than anything else, but you can reduce it even further...

Domove(<
(float)((msg == "left";) - (msg == "right";)),
(float)((msg == "fwd";) - (msg == "back";)),
(float)((msg == "up";) - (msg == "down";))
> * d);
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!

http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal

http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
01-03-2008 09:55
/me throws a humbug at Ordinal.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Ace Cassidy
Resident Bohemian
Join date: 5 Apr 2004
Posts: 1,228
01-03-2008 10:05
From: Ordinal Malaprop
This is posted more for doubtful scripting humour value than anything else, but you can reduce it even further...

Domove(<
(float)((msg == "left";) - (msg == "right";)),
(float)((msg == "fwd";) - (msg == "back";)),
(float)((msg == "up";) - (msg == "down";))
> * d);


If and when we have an obfuscated code contest for LSL, this gets my first nomination.

:)

- Ace
_____________________
"Free your mind, and your ass will follow" - George Clinton
Lish Lach
Registered User
Join date: 5 Aug 2006
Posts: 33
01-03-2008 12:59
From: Ace Cassidy
If and when we have an obfuscated code contest for LSL, this gets my first nomination.

It's not obfuscated code, it's data-driven programming, and probably as elegant as LSL script will ever get. Conditional logic is a vice, not a virtue.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-03-2008 13:29
Very kind of you to say so! I actually use that method in the control event for my Mechanical Dragonfly Wings, though since that uses bitfields it is - visually speaking - even uglier.
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!

http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal

http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-04-2008 07:30
looks scarily like something I did recently, multplying elements of a vector by a negated boolean to get conditional additive inverses for certain rotations, in a control event you could have more fun, choosing whether or not to normalize for multiple directional inputs
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Okiphia Anatine
Okiphia Rayna
Join date: 22 Nov 2007
Posts: 454
01-04-2008 10:30
From: Void Singer
looks scarily like something I did recently, multplying elements of a vector by a negated boolean to get conditional additive inverses for certain rotations, in a control event you could have more fun, choosing whether or not to normalize for multiple directional inputs

o.o was that english?

Its sentences like that that make me wonder if I'm ever going to be a competent scriptor XD
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
01-04-2008 23:23
If you are passing this object to others, there is one thing that stands out to me - a common problem with "listen" scripts, they establish a listen to their owner when the script is reset, but do not reset when they change owners... You can cure this by adding a changed() event handler (resetting the script again is the simplest way to do it but there are other ways):

changed(integer change)
{
if (change & CHANGED_OWNER)
llResetScript();
}

This will clear all the variables and establish the script as listening to the new owner.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-05-2008 10:40
From: Okiphia Anatine
o.o was that english?

Its sentences like that that make me wonder if I'm ever going to be a competent scriptor XD

sorry, my lova of abusing math at work, the code is actually much simpler than it sounds

I had a user defined vector that had a one for each axis your wanted to rotate on, multiplied by a boolean value (true false) which was negated (*-1), then each element(xyz) was multipled by the objects vector rotation (also xyz) to eliminate rotations I didn't want.

roughly...
userVector = <1, 1, 0>;
someBoolean = TRUE;
objectRot = llGetRot();

userVector *= someBoolean - 1;
objectRot.x += objectRot.x * userVector.x; //repeat for y and z

it was entirely too complex in it's original form (which this is only part of), and got trashed as being inelegant and hard for users... ordinal's solution above IS elegant though, and in a control event for a vehicle could benefit from the addition of lllVecNorm() if applied directly to thrust (to keep it from turning faster than it moves in a single direction)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -