Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

help joining 2 scripts is much appreciated

Isis Ophelia
Registered User
Join date: 16 Mar 2006
Posts: 18
05-07-2008 06:07
I am building a set of seats, which should change color and offer the choice of different sit animations when touched. For that purpose I have 2 free scripts that I found somewehre long ago. One of the scripts its a multiple animations changer with dialog script, the other is a color changer both react on touch. I have inserted both scripts in the seat prims, when I touch a seat to change the color, the dialog menu for the animations changer also opens, so I need to ignore the one I dont need. I have copied and pasted one of the scripts into the other, but then I get a syntax error (uff no wonders coz my scripting knowledge is 0). I am pasting both scripts here in the hope that someone can help me to tweak them together.

This is the multiple sit w/dialog:

// written by Norman Desmoulins
// Multiple Sit w/Dialog

vector sitPosition = <0.0, 0.0, 0.73>;
string sitText = "";
string sitAnim = "";
integer sitAnimIndex;

integer showAnim;
integer listenHandle = 0;
integer listenChannel;

hidePoseBall()
{
showAnim = FALSE;
llSetAlpha(0.0, ALL_SIDES);
llSetText(" ", <0,0,0>,0.0);
}

showPoseBall()
{
showAnim = TRUE;
llSetAlpha(1.0, ALL_SIDES);
llSetText(sitText, <1,1,1> , 1);
}

getText()
{
sitAnim = llGetInventoryName(INVENTORY_ANIMATION,sitAnimIndex );
sitText = llGetObjectDesc();
if ((llStringLength(sitText)==0) || (sitText==";(No Description)";))
sitText = sitAnim;
}

default
{
state_entry()
{
listenChannel = (integer)(llFrand(1.0) * 10000.0 + 1000.0);
if (listenHandle != 0)
llListenRemove(listenHandle);
listenHandle = llListen(listenChannel, "", NULL_KEY, "";);

getText();
llSetSitText(sitText);
llSitTarget(sitPosition, ZERO_ROTATION);
llSetText(sitText, <1,1,1> , 1);
}

touch_start(integer changes)
{
list poseList;
integer j;
integer i;
j = llGetInventoryNumber(INVENTORY_ANIMATION);
for (i = 0; i < j; i++)
{
string name = llGetInventoryName(INVENTORY_ANIMATION, i);
poseList = poseList + [name];
}
llDialog(llDetectedKey(0), "Select pose", poseList, listenChannel);
}

listen(integer c, string n, key id, string m)
{
sitAnimIndex = 0;
integer j;
integer i;
j = llGetInventoryNumber(INVENTORY_ANIMATION);
for (i = 0; i < j; i++)
{
string name = llGetInventoryName(INVENTORY_ANIMATION, i);
if (name==m)
{
sitAnimIndex = i;
i = j;
}
}

sitText = m;
if (showAnim)
{
llSetText(sitText, <1,1,1> , 1);
}
else
{
integer perm = llGetPermissions();
if ((perm & PERMISSION_TRIGGER_ANIMATION) && llStringLength(sitAnim)>0)
{
llStopAnimation(sitAnim);
llStartAnimation(m);
}
}
sitAnim = m;
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
if (llAvatarOnSitTarget() != NULL_KEY)
{
llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION);
}
else
{
integer perm = llGetPermissions();
if ((perm & PERMISSION_TRIGGER_ANIMATION) && llStringLength(sitAnim)>0)
llStopAnimation(sitAnim);
showPoseBall();
}
}
else if (change & CHANGED_INVENTORY) llResetScript();
}

run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("sit";);
getText();
llStartAnimation(sitAnim);
hidePoseBall();
}
}
}

---------------------------------------------------------------
and this one the color changer on touch:

//Color changing script

list grayscale =["black",<0,0,0>,"white",<1,1,1>,"gray",<0.5,0.5,0.5>,"silver",<0.75,0.75,0.75>,"darkgray",<0.4,0.4,0.4>,
"lightgrey",<0.83,0.83,0.83>];
list reds = ["red",<1,0,0>,"darkred",<0.55,0,0>,"crimson",<0.86,0.08,0.24>,"indianred",<0.8,0.36,0.36>,
"orangered",<1,0.27,0>];
list pinks = ["hotpink",<1,0.41,0.71>,"pink", <1,0.75,0.8>,"lightpink",<1,0.71,0.76>,"deeppink",<1,0.08,0.58>,
"fuchsia",<1,0,1>,"orchid",<0.85,0.44,0.84>,"plum",<0.87,0.63,0.87>];
list violets = ["violet",<0.8,0.51,0.8>,"indigo",<0.29,0,0.51>,"lavender",<0.7,0.7,1>,"magenta",<1,0,1>,
"purple",<0.5,0,0.5>,"darkmagenta",<0.55,0,0.55>,"darkviolet",<0.58,0,0.83>,"blueviolet",<0.54,0.17,0.89>];
list dk_blues = ["darkblue",<0,0,0.55>,"blue",<0,0,1>,"deepskyblue",<0,0.75,1>,"mediumblue",<0,0,0.8>,
"midnightblue",<0.1,0.1,0.44>,"royalblue",<0.25,0.41,0.88>,"slateblue",<0.42,0.35,0.8>,"steelblue",<0.27,0.51,0.71>];
list lt_blues = ["teal",<0,0.5,0.5>,"turquoise",<0.25,0.88,0.82>,"darkcyan",<0,0.55,0.55>, "lightblue", <0.68,0.85,0.9>,
"aquamarine",<0.5,1,0.83>,"azure",<0.8,1,1>,"cyan",<0,1,0.9>,"skyblue",<0.53,0.81,0.92>];
list yellows = ["yellow",<1,1,0>,"gold",<1,0.84,0>,"lightyellow",<1,1,0.88>,"goldenrod",<0.85,0.65,0.13>,
"yellowgreen",<0.6,0.8,0.2>];
list dk_greens = ["darkgreen",<0,0.39,0>,"green",<0,0.5,0>,"forestgreen",<0.13,0.55,0.13>,"lawngreen",<0.49,0.99,0>,
"springgreen",<0,1,0.5>];
list lt_greens = ["lightgreen",<0.56,0.93,0.56>,"chartreuse",<0.5,1,0>,"greenyellow",<0.68,1,0.18>,"honeydew",<0.94,1,0.94>,
"limegreen",<0.2,0.8,0.2>,"mintcream",<0.96,1,0.98>,"seagreen",<0.18,0.55,0.34>];
list oranges = ["orange",<1,0.65,0>,"darkorange",<1,0.55,0>,"coral",<1,0.5,0.31>,"navajowhite",<1,0.87,0.68>,
"salmon",<0.98,0.5,0.45>,"seashell",<1,0.96,0.93>,"brown",<.24,.17,.15>];

//Typically you wouldn't change anything below here, but if you're feelin it, who's gonna stop you?!
//---------------------------------------------------------

integer channel;
integer listen_handle;
key owner;
list sub_menu;
list main_menu = ["grayscale", "reds", "pinks", "violets", "dk_blues", "lt_blues", "yellows", "dk_greens", "lt_greens", "oranges"];


init() {
llListenRemove(listen_handle);
owner = llGetOwner();
channel = llFloor(llFrand(2000000)); //random channel so multiple scripts don't interfere with each other
listen_handle = llListen(channel, "", owner, "";);
}


default
{
on_rez(integer s) { init(); }
state_entry() { init(); }

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

if (llListFindList(main_menu, [message]) != -1) {
if (message == "grayscale";) sub_menu = grayscale;
else if (message == "reds";) sub_menu = reds;
else if (message == "pinks";) sub_menu = pinks;
else if (message == "violets";) sub_menu = violets;
else if (message == "dk_blues";) sub_menu = dk_blues;
else if (message == "lt_blues";) sub_menu = lt_blues;
else if (message == "yellows";) sub_menu = yellows;
else if (message == "dk_greens";) sub_menu = dk_greens;
else if (message == "lt_greens";) sub_menu = lt_greens;
else if (message == "oranges";) sub_menu = oranges;

llDialog(owner, "\n\nSelect a color", llList2ListStrided(sub_menu, 0, -1, 2), channel);
return;
}

integer index = llListFindList(sub_menu, [message]);
if (index != -1) {
vector color_vector = llList2Vector(sub_menu, index+1);
if (llGetLinkNumber() == 1) llSetLinkColor(LINK_SET, color_vector, ALL_SIDES); //If it's root prim, do whole set
else llSetColor(color_vector, ALL_SIDES); //otherwise, just do that prim
}

}

touch_start(integer s) {
if (llDetectedKey(0) == owner) {
llDialog(owner, "\n\nSelect a color group", main_menu, channel);
}
}
}

---------------------------------------------------------------
Many thanks in advance :-)
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
05-07-2008 09:45
You're going to need to know more than zero about scripts to be able to do this. You don't have to be a wizard, though, so hang in there.

Variable definitions have to preceed any use in functions. Example variable definition:

From: someone
integer showAnim;
Function definitions have to come before any states. Example function definition:

From: someone
hidePoseBall()
{
showAnim = FALSE;
llSetAlpha(0.0, ALL_SIDES);
llSetText(" ", <0,0,0>,0.0);
}


The first state definition is "default".

There can be only one "default". In these two scripts, that's the only state, so you don't have to worry about other states. However, you'll have to combine the two "default" states into one. This is nontrivial; sometimes it's easy and other times you have to do some careful thinking.

To combine the two default states into one:

The things inside the state definition are event handlers, for example, on_rez.

For each handler that's only in one script, no problem, put it in your combined default state.

For each handler that's used in both scripts, you'll have to decide what you want that handler to do to handle both functions.

BUT -- before you get too far with any of this, you have to figure out what behavior you want. Currently, if you use both scripts, you get two menus.

What do you WANT it to do when you touch it? Do you want to combine the two menus into one, or present a main menu with two options (color or animation)?

To do the latter, you'll need to know how to create the main menu (not hard, see for more info). You'll also need to know how to handle the response in the "listen" handler.

If you're asking someone to just please do it for you ... well, you may have better luck posting on the products wanted forum and offering something in return. If you're asking for advice and trying to learn how to do this yourself, then see how far you can get with what I've told you and try to learn as much as you can about scripts and post back with questions.

There's a pitfall I didn't mention above, if the two scripts use the same name for some variable. If so, they're either using it for the same purpose or different ones. In the latter case, it's generally easiest to simply change all occurences in the second script to a new name.

We're happy to help you learn to script.
Isis Ophelia
Registered User
Join date: 16 Mar 2006
Posts: 18
05-07-2008 22:36
thank you a lot Lear that you took the time for this very detailled explanation

I got yesterday the book: second life programmierung mit der linden scripting language.... it is in German, but well I hope it will make it easier for me to understand scripting and to learn. I wish there were such books in Spanish (my mother tongue) but no luck, maybe somewhen in few years