Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Multi-use command and vehicle doors

Myiasia Wallaby
Registered User
Join date: 20 Mar 2005
Posts: 79
10-29-2005 18:43
First, the issue that's been bothering me for a long time that I just can't figure out for the life of me: Getting a door on a vehicle that doesn't break (IE; lose its rotational position or rotate the wrong way, or in some extreme cases, "fall off" but remain linked to the parent object) when the vehicle changes its position. I see people doing it with these vehicles all the time, but for the life of me can't figure out how to get it to work.

Second issue that I'm unsure of how to go about is making a command that uses variables. For example, I have an elevator I wish to parse the word "set" followed by stuff like "first", so that when the owner says "set first", it'll set its current position as the first floor. I know one way to go about it, but it requires that I wrote several chunks of code.. my current implimentation is the following:

llListen(4338,"","","Ground";);
llListen(4338,"","","First";);
llListen(4338,"","","Second";);
llListen(4338,"","","Third";);
llListen(4338,"","","Fourth";);
llListen(4338,"","","Fifth";);
llListen(4338,"","","Sixth";);
llListen(4338,"","","Seventh";);
llListen(4338,"","","Eighth";);
llListen(4338,"","","Roof";);

Which it refers to:

if(m=="Ground";)
{
end=pos;
llMoveToTarget(end,1.0);
llTriggerSound("Elevator Call", 1.0);
}

if(m=="First";)
{
end=<80,100,58.675>;
llMoveToTarget(end,1.0);
llTriggerSound("Elevator Call", 1.0);
}

And so-on. This is annoyingly repetitive, so I'm wanting to shrink it down to use the same hunk of code, using a "set" command to set the vectors in.. well, a vector for each floor, so that all I end up using is one hunk of code that has all the if statements in that.. I'm guessing it's an if/else statement string inside an if statement, but I don't know how to call up a second word. Like in C++ and other languages, be it scripting or otherwise, it's be $2 to return the second string in a given statement, and $3 for the third etc..

Any help is greatly appreciated in both respects.
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
10-29-2005 21:53
CODE


string command;

default
{
state_entry()
{
llListen(channel, "", NULL_KEY, "")
}

listen(integer channel, string name, key id, string message)
{
command = llGetSubString(message, 0, 2)
if(command == "set")
{
message = llGetSubString(message, 3, -1)
{
if(message == "first")
{
//do something
}
}
}
}
}



That should help your many listens
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Myiasia Wallaby
Registered User
Join date: 20 Mar 2005
Posts: 79
10-29-2005 23:13
Thanks, Ken!
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
10-29-2005 23:30
From: Myiasia Wallaby
First, the issue that's been bothering me for a long time that I just can't figure out for the life of me: Getting a door on a vehicle that doesn't break (IE; lose its rotational position or rotate the wrong way, or in some extreme cases, "fall off" but remain linked to the parent object) when the vehicle changes its position. I see people doing it with these vehicles all the time, but for the life of me can't figure out how to get it to work.

Welcome to the world of llSetLocalRot, or the joys of object-relative coordinates ;) A door prim on a vehicle is a child prim, which means that when it calls llSetPos, it sets its local position relative to the root prim, instead of its position relative to the region. BUT you must call llSetLocalRot and not llSetRot to set the rotation relative to the root prim instead of relative to the region... I still don't know why this is so inconsistent :o

Example code for rotating a child prim back and forth:
CODE

rotation lrot;
integer IS_OPEN;
rotation ropen;

default
{
state_entry()
{
lrot = llGetLocalRot();
IS_OPEN = FALSE;
ropen = llEuler2Rot(<0,0,PI_BY_TWO>);
}

touch_start(integer i)
{
//if (llDetectedKey(0) != llGetOwner()) return;
// uncomment to make the door respond only to you

if (IS_OPEN)
{
IS_OPEN = FALSE;
llSetLocalRot(lrot);
} else {
IS_OPEN = TRUE;
llSetLocalRot(ropen * lrot);
}
}
}
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Myiasia Wallaby
Registered User
Join date: 20 Mar 2005
Posts: 79
Thanks!
11-14-2005 12:42
This will certainly come in handy. :)