Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Menu Driven Texture Script

DjBlacky McMahon
Registered User
Join date: 26 May 2008
Posts: 10
08-13-2008 08:21
From: Pale Spectre
The buttons and their corresponding colours are controlled by these two lists:

list COLOR_LIST = ["white", "red", "green","blue", "yellow", "orange","purple", "pink", "cyan", "off", "random"];
list COLOR_VALUE = [<1, 1, 1>, <1, .0, .0>, <0, 1, 0>, <0, 0, 1>, <1, 1, 0>, <1, .05, .0>, <1, 0, 1>, <1, .02, .02>, <0, 1, 1>];

So, white = <1, 1, 1,>, red = <1, 0, 0>, etc. ...change these values to whatever colours you want.

Note: in RBG World, 1 = 255, so, for example, <1, 0.05, 0> is approximately the same as RBG(255, 13, 0).

See:


thats not what i would *sorry i have write that false in the last thread*
so i whant the the coulor changes at the same time as the light change...
so when the light turns to red the prim should turn to red to
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
08-13-2008 11:12
From: Amy Stork
I didn't have any trouble getting this to work... but how do I keep the blue menu up so that you can change colour many times without clicking?
That one should be an easy modification you can make for yourself. :) To make the blue dialog menu appear automatically you will need to have the code in the touch_start Event handler:

HANDLE = llListen(CHANNEL, "", NULL_KEY, "";);
llDialog(llDetectedKey(0), "Color?", COLOR_LIST, CHANNEL); // This is the blue menu doohickey

...also appear following the call to pColor() in the listen Event handler.


From: DjBlacky McMahon
thats not what i would *sorry i have write that false in the last thread* so i whant the the coulor changes at the same time as the light change... so when the light turns to red the prim should turn to red to
It should be doing that already. This is the code that causes the light (PRIM_POINT_LIGHT) and colour (PRIM_COLOR) to change:

llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, color, INTENSITY, RADIUS, FALLOFF,
PRIM_COLOR, FACE, color, llGetAlpha(FACE),
PRIM_GLOW, FACE, 1.0]);

...both the PRIM_POINT_LIGHT, and the PRIM_COLOR, settings are using the same variable to assign their colour: color.

Notice, however, that the colour, and the glow, are only being applied to the one face (FACE = 5). FACE = -1 (aka ALL_SIDES) will give you an interesting result. ;)

I think it's time to stop looking for Scripting Tips and start experimenting. :D
Amy Stork
Way past use by date
Join date: 26 Feb 2006
Posts: 646
08-13-2008 13:37
From: Pale Spectre
That one should be an easy modification you can make for yourself. :) To make the blue dialog menu appear automatically you will need to have the code in the touch_start Event handler:

HANDLE = llListen(CHANNEL, "", NULL_KEY, "";);
llDialog(llDetectedKey(0), "Color?", COLOR_LIST, CHANNEL); // This is the blue menu doohickey

...also appear following the call to pColor() in the listen Event handler.



Hi thanks for the reply - that was in fact what i tried first but i can't get it to work... I tried commenting out the //llListenRemove(HANDLE); bit as it looked suspicious but still not a sausage thus far... any more tips?

Here is the code i made ( I took out the glow and the random thingy )

From: someone

integer HANDLE;
integer CHANNEL = -44567;
float INTENSITY = -1;
float RADIUS = 0.0;
float FALLOFF = 0.0;
integer FACE = 5;

list COLOR_LIST = ["white", "red", "green",
"blue", "yellow", "orange",
"purple", "pink", "cyan", "off"];
list COLOR_VALUE = [<1, 1, 1>, <1, .0, .0>, <0, 1, 0>,
<0, 0, 1>, <1, 1, 0>, <1, .05, .0>,
<1, 0, 1>, <1, .02, .02>, <0, 1, 1>];

pColor(vector color)
{
llSetPrimitiveParams([PRIM_COLOR, FACE, color, llGetAlpha(FACE)]);
}

default
{
touch_start(integer total_number)
{
HANDLE = llListen(CHANNEL, "", NULL_KEY, "";);
llDialog(llDetectedKey(0), "Color?", COLOR_LIST, CHANNEL);
}

listen(integer channel, string name, key id, string message)
{
//llListenRemove(HANDLE);
if(message == "off";)
{
llSetTimerEvent(0.0);
llSetPrimitiveParams([PRIM_COLOR, FACE, <.95, .95, .95>, llGetAlpha(FACE)]);
llWhisper(0,"Lights out";);
}
else
{
llSetTimerEvent(0.0);
integer i = llListFindList(COLOR_LIST, [message]);
vector color = llList2Vector(COLOR_VALUE, i);
pColor(color);
llOwnerSay(message);
llWhisper(0,"Done";);
}

HANDLE = llListen(CHANNEL, "", NULL_KEY, "";);
llDialog(llDetectedKey(0), "Color?", COLOR_LIST, CHANNEL);

}


}
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
08-13-2008 14:18
Replace the llDetectedKey() with id and it should all start working:

llDialog(id, "Color?", COLOR_LIST, CHANNEL);


llDetectedKey() was never going to work inside the listen Event handler. :o
Amy Stork
Way past use by date
Join date: 26 Feb 2006
Posts: 646
08-13-2008 14:46
Hehe that worked thanks :)

Now to change it from a colour changing script to a menu driven texture changing script to get back on topic...

I'm guessing that should be fairly straighforward by changing pColor(); to a pTexture(); although I need to work out how to pass a string rather than an int of course...
Amy Stork
Way past use by date
Join date: 26 Feb 2006
Posts: 646
08-13-2008 15:23
Here's the working Menu Driven Texture Script with a persistent menu :)

From: someone

//Menu Driven Texture Script

integer HANDLE;
integer CHANNEL = -44567;
integer FACE = 5;
integer REPEATX = 1;
integer REPEATY = 1;
integer OFFSETX = 0;
integer OFFSETY = 0;

list TEXTURE_LIST = ["Texture 1", "Texture 2", "Texture 3", "Off"];
list TEXTURE_VALUE = ["Texture1", "Texture2", "Texture3", TEXTURE_BLANK];

pTexture(string texture)
{

llSetPrimitiveParams([PRIM_TEXTURE, FACE, texture, <REPEATX, REPEATY, 0.0>,<OFFSETX,OFFSETY, 0.0>, 0.0 ]);

}

default
{
touch_start(integer total_number)
{
HANDLE = llListen(CHANNEL, "", NULL_KEY, "";);
llDialog(llDetectedKey(0), "Choose Texture:", TEXTURE_LIST, CHANNEL);
}

listen(integer channel, string name, key id, string message)
{
llListenRemove(HANDLE);
if(message == "Off";)
{
llSetTimerEvent(0.0);

llSetPrimitiveParams([PRIM_TEXTURE, FACE, TEXTURE_BLANK, <REPEATX, REPEATY, 0.0>,<OFFSETX,OFFSETY, 0.0>, 0.0 ]);
llWhisper(0,"Lights out";);
}
else
{
llSetTimerEvent(0.0);
integer i = llListFindList(TEXTURE_LIST, [message]);
string texture = llList2String(TEXTURE_VALUE, i);

llOwnerSay(texture);


pTexture(texture);

HANDLE = llListen(CHANNEL, "", NULL_KEY, "";);
llDialog(id, "Choose Texture:", TEXTURE_LIST, CHANNEL);

}
}


}
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
Minimalist without Cross-Talk...
08-14-2008 13:02
Good job... now lets clean out the redundant llSetTimerEvent lines, remove the duplicate llDialog code, acknowledge that the button called: "Off" has its own texture, lose the llSetPrimitiveParms (which doesn't seem to be doing much anymore), and guard against cross-talk on the listen...

CODE

integer HANDLE;
integer FACE = 5;

list TEXTURE_LIST = ["Texture 1", "Texture 2", "Texture 3", "Off"];
list TEXTURE_VALUE = ["Texture1", "Texture2", "Texture3", TEXTURE_BLANK];

pShowDialog(key id)
{
llListenRemove(HANDLE);
integer CHANNEL = ((integer)llFrand(900000) + 100000) * -1;
HANDLE = llListen(CHANNEL, "", NULL_KEY, "");
llDialog(id, "\nChoose Texture:", TEXTURE_LIST, CHANNEL);
}

default
{
touch_start(integer total_number)
{
pShowDialog(llDetectedKey(0));
}

listen(integer channel, string name, key id, string message)
{
integer i = llListFindList(TEXTURE_LIST, [message]);
string texture = llList2String(TEXTURE_VALUE, i);
llOwnerSay(texture);
llSetTexture(texture, FACE);
pShowDialog(id);
}
}


:D
Danger359 Nightfire
Registered User
Join date: 29 Dec 2007
Posts: 9
Fantastic job
09-12-2008 20:11
This is great. Exactly what I was looking for.

In my application I used llSetLinkPrimitiveParams to change the texture of the entire link set. It works great!

Suggested enhancement: build the Texture List automatically from the prim's inventory, perhaps using the Description field to provide info / name for the menu button since texture names are often indecipherable.
Dragonlady Boa
Registered User
Join date: 13 Jul 2007
Posts: 18
09-25-2008 10:42
how can I change this one to just smoothly cycle the colors, without a texture being specified so i can just use the texture that I already have applied to the different sides. Also a little slower of a change would be nice as well.



//Use any texture key. "5748decc-f629-461c-9a36-a35a221fe21f" is blank.
key Texture = "5748decc-f629-461c-9a36-a35a221fe21f";

float Mag;
integer Time;
float Power = 0.7;
float Prefix = 0.25;

default
{
state_entry()
{
llSetColor(<1, 1, 1>, ALL_SIDES);
llSetTexture(Texture, ALL_SIDES);
Mag = llPow(2, (1 / Power)) / 2;
llSetTimerEvent(0.04);
}

timer()
{
vector Color;
Color.x = Prefix * Mag * llPow(llCos(Time * PI / 30) + 1, (1 / Power));
Color.y = Prefix * Mag * llPow(llCos((Time + 20) * PI / 30) + 1, (1 / Power));
Color.z = Prefix * Mag * llPow(llCos((Time + 40) * PI / 30) + 1, (1 / Power));

llSetColor(Color, ALL_SIDES);

Time++;
if(Time >= 720) { Time = 0; }
}
}
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
09-25-2008 12:00
CODE

//Use any texture key. "5748decc-f629-461c-9a36-a35a221fe21f" is blank.
key Texture = "5748decc-f629-461c-9a36-a35a221fe21f";

float Mag;
integer Time;
float Power = 0.7;
float Prefix = 0.25;

default
{
state_entry()
{
llSetColor(<1, 1, 1>, ALL_SIDES);
llSetTexture(Texture, ALL_SIDES); // <=== this is setting the texture [1]
Mag = llPow(2, (1 / Power)) / 2;
llSetTimerEvent(0.04); // <=== this is setting the timer speed [2]
}

timer()
{
vector Color;
Color.x = Prefix * Mag * llPow(llCos(Time * PI / 30) + 1, (1 / Power));
Color.y = Prefix * Mag * llPow(llCos((Time + 20) * PI / 30) + 1, (1 / Power));
Color.z = Prefix * Mag * llPow(llCos((Time + 40) * PI / 30) + 1, (1 / Power));

llSetColor(Color, ALL_SIDES);

Time++;
if(Time >= 720) { Time = 0; }
}
}



[1] Commenting out this line will preserve the original texture.

[2] The timer is currently set to 0.04 seconds. Increasing this number will slow down the colour change.
Dragonlady Boa
Registered User
Join date: 13 Jul 2007
Posts: 18
09-25-2008 12:39
TYTY! one more tiny question and I'll stop bugging people. How do I use this for linked items to make all the prims change at one time. I tried setting in a linked param, and kept getting an error on the syntax
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
09-25-2008 12:47
llSetColor(Color, ALL_SIDES);

...will need to become its close cousin...

llSetLinkColor(LINK_SET, Color, ALL_SIDES);

...and that should do it. :)
Dragonlady Boa
Registered User
Join date: 13 Jul 2007
Posts: 18
09-25-2008 12:51
Perfect! TYSVM! Again LOL. sorry for bugging everyone
Joelle Robbiani
Registered User
Join date: 14 Jun 2008
Posts: 0
Script not working?
11-21-2009 05:14
I tried using the script examples from both Max and Pale, but the color of the prim doesn't change. The menu fires up but when I choose one of the colors nothing changes. The viewer I'm currently using is Second Life 1.23.5 (136274) Oct 14 2009 13:31:23 (Second Life Release Candidate). Not sure if this version is causing the problem. Any ideas?

Thanks!
1 2