Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Corner rezzes walls

Kenedy Drebin
Registered User
Join date: 8 Aug 2007
Posts: 2
11-05-2009 14:29
So I'm trying to build a basic architectural feature that creates its own walls and then deletes them when done. The main part is a corner (hollowed prim, half cut out) and a set of 2 prim wall pieces. The corner uses a dialog box to give options to add walls (open), remove walls(close), and three color options that will recolor the necessary faces.

Right now, I am having problems with getting the child portion of the wall pieces to change colors, and occasionally parts will not unlink.

Here is the corner script:
float xOffset = 0.5;
float yOffset = -0.5;
float delay = 0.1;
integer CHAN = 711;
list MENU = ["red", "blue", "green", "open", "close"];
vector color;
vector red = <9,0,0>;
vector green = <0,9,0>;
vector blue = <0,0,9>;

default
{
state_entry()
{
llSay(0, "Corner Active";);
llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);
llListen(CHAN, "", NULL_KEY, "";);
}
touch_start(integer num_detected)
{
llDialog(llDetectedKey(0), "Menu", MENU, CHAN);
}
listen(integer channel, string name, key id, string message)
{
if(message == "open";) //Rez wall peices
{
llRezObject("SlideY1", llGetPos() + <0, 1 * yOffset, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
llRezObject("SlideX1", llGetPos() + <1 * xOffset, 0, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
llSleep(delay);
llRezObject("SlideY2", llGetPos() + <0, 2 * yOffset, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
llRezObject("SlideX2", llGetPos() + <2 * xOffset, 0, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
llSleep(delay);
llRezObject("SlideY3", llGetPos() + <0, 3 * yOffset, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
llRezObject("SlideX3", llGetPos() + <3 * xOffset, 0, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
llSleep(delay);
llRezObject("SlideY3", llGetPos() + <0, 4 * yOffset, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
llRezObject("SlideX3", llGetPos() + <4 * xOffset, 0, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
llSleep(delay);
llRezObject("SlideY3", llGetPos() + <0, 5 * yOffset, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
llRezObject("SlideX3", llGetPos() + <5 * xOffset, 0, 0>, ZERO_VECTOR, ZERO_ROTATION, 711);
}

else if(message == "close";) //unlink wall peices
{
integer i;
for(i=0; i<20; i++)
{
llBreakLink(2);
}

}

else if(message == "red";) //change color to red
{
llSetColor(red, 0);
llSetColor(red, 1);
llSetColor(red, 3);
llSetColor(red, 4);
llSetColor(red, 5);
llSetColor(red, 6);
}

else if(message == "green";) //change color to green
{
llSetColor(green, 0);
llSetColor(green, 1);
llSetColor(green, 3);
llSetColor(green, 4);
llSetColor(green, 5);
llSetColor(green, 6);
}

else if(message == "blue";) //change color to blue
{
llSetColor(blue, 0);
llSetColor(blue, 1);
llSetColor(blue, 3);
llSetColor(blue, 4);
llSetColor(blue, 5);
llSetColor(blue, 6);
}

}

object_rez(key id) //link wall peices
{
if(llGetPermissions() & PERMISSION_CHANGE_LINKS)
{
llCreateLink(id, TRUE);
color = llGetColor(1);
if(color = red)
{
llSay(CHAN, "red";);
}
else if(color = green)
{
llSay(CHAN, "green";);
}
else if(color = blue)
{
llSay(CHAN, "blue";);
}
}
}
}

And the wall pieces script (located in both prims)
integer CHAN = 711;
vector red = <9,0,0>;
vector green = <0,9,0>;
vector blue = <0,0,9>;

default
{
changed(integer change)
{
if (change & CHANGED_LINK) // linked/unlinked/sat on
{
if (llGetLinkNumber() == 0) // now i'm a single prim linked to nothing
{
llDie(); // so i die
}
else
{
llListen(CHAN, "", NULL_KEY, "";);
}
}
}

listen(integer channel, string name, key id, string message)
{
if(message == "red";)
{
llSetColor(red, 0);
llSetColor(red, 1);
llSetColor(red, 3);
llSetColor(red, 4);
llSetColor(red, 5);
llSetColor(red, 6);
}
else if(message == "green";)
{
llSetColor(green, 0);
llSetColor(green, 1);
llSetColor(green, 3);
llSetColor(green, 4);
llSetColor(green, 5);
llSetColor(green, 6);
}
else if(message == "blue";)
{
llSetColor(blue, 0);
llSetColor(blue, 1);
llSetColor(blue, 3);
llSetColor(blue, 4);
llSetColor(blue, 5);
llSetColor(blue, 6);
}
}
}

There is probably a lot of inefficiency in here, I'm still kind of new to scripting in general. Any help would be greatly appreciated.
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
11-07-2009 00:52
I see a little typo in you object_rez() event.

if (color = whatever)

Should be:

if (color == whatever) // "==" is comparison.

Any way, all these tests are inefficient. I would use global lists.

list ColorName = [red, green, blue];
list ColorValue = [<9, 0, 0>, <0, 9, 0>, <0, 0, 9>];

So you can do:

integer k = llListFindList(ColorName, [message]);
if (k != -1)
{
llSetColor(llList2Vector(ColorValue, k), ALL_SIDES);
}

Or the opposite:

integer k = llListFindList(ColorValue, [color]);
if (k != -1)
{
llSay(CHAN, llList2String(ColorName, k));
}

However llCreateLink() will always link new prims as child number 2 and beyond so the whole chat thing is better replaced with a simple:

llSetLinkColor(2, color, ALL_SIDES);
//llSetLinkColor(3; color, ALL_SIDES); // For a second prim, and so on...

One tiny irritating detail: Whaterever this object says, this is for the owner only so make it talk only to the owner with llOwnerSay("Whatever";); (Everybody hates spam.)

As for breaking all links, llBreakAllLinks() should be better than anything. No? ;)

And remove all those llSleep() in between the rezzings. You can't rez faster than what the system allows. llSleep() is evil. Its actual name should rather be llDeepComa() because when you use it, your script has a Near Death Experience. It really does nothing, hears nothing... especially the events that are piling up in the event queue. Evil! Evil! ;)

Any way, I wouldn't do the rezzing this way but prim by prim from within the object_rez() event. I'll show you how if you ask. For the moment, I think you have enough food for your brain...
Kenedy Drebin
Registered User
Join date: 8 Aug 2007
Posts: 2
11-11-2009 13:21
Thank you for all of the help Kaluura, the script is running beautifully now.