Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Texture picker

dave2bwhipped Ansar
Registered User
Join date: 3 Oct 2008
Posts: 17
02-04-2009 09:10
OK, so what I want to do is have a dialog menu system with different type of textures to pick out.

I am not sure if its just as simple as changing the color picker statements but I can seem to get it right.

Can some one help? Thanks



integer listen_channel = 2; // Channel to listen for color commands

list colors = [ // List of named colors recognized
"yellow", <1.0, 1.0, 0.0>,
"cyan", <0.0, 1.0, 1.0>,
"blue", <0.0, 0.0, 1.0>,
"green", <0.0, 1.0, 0.0>,
"red", <1.0, 0.0, 0.0>,
"salmon", <1.0, 0.5, 0.5>,
"pink", <1.0, 0.3, 0.6>,
"black", <0.0, 0.0, 0.0>,
"white", <1.0, 1.0, 1.0>
];

list link_channels = [ // Channels for linked prim groups like "straps"
"straps", 5,
"base", 2
];

integer callback; // Used to cleanup old listeners.

vector parse_named_color(string color_name)
{
vector color = <-1, -1, -1>;
integer index = 0;
integer stride = 2;
integer length = llGetListLength(colors);
integer found = FALSE;
color_name = llToLower(color_name);
do{
if(color_name == llList2String(colors, index))
{
color = llList2Vector(colors, index + 1);
found = TRUE;
}
index += stride;
}while(index < length && !found);
return color;
}

activate()
{
callback = llListen(listen_channel, "", llGetOwner(), "";);
llOwnerSay("Color Changer v1.0 Activated";);
llOwnerSay("Use chat commands to set the color of the entire object.";);
llOwnerSay("For instance say /" + (string) listen_channel + " color red";);
llOwnerSay("You can also say /" + (string) listen_channel + " color 1 0 0";);
llOwnerSay("To set individual parts use: ";);
integer index = llGetListLength(link_channels) - 1;
integer stride = 2;
do
{
llOwnerSay("/" + (string) listen_channel + " " + llList2String(link_channels, index - 1) + " color blue";);
index -= stride;
}while(index > 0);
}

deactivate()
{
llListenRemove(callback);
llOwnerSay("Color Changer v1.0 Deactivated. Touch to reactivate.";);

}

set_all(list args)
{
vector color = <0,0,0>;
if(llGetListLength(args) == 2)
{
color = parse_named_color(llList2String(args, 1));
}
else if(llGetListLength(args) >= 4)
{
color = <llList2Float(args, 1), llList2Float(args, 2), llList2Float(args, 3)>;
}
if(color == <-1, -1, -1>;)
{
llOwnerSay("Unable to find color";);
}
else
{
llOwnerSay("Setting color of all to: " + (string) color);
llSetColor(color, ALL_SIDES);
integer index = llGetListLength(link_channels) - 1;
integer stride = 2;
string message = "color " + (string) color.x + " " + (string) color.y + " " + (string) color.z;
do
{
llMessageLinked(LINK_ALL_OTHERS, llList2Integer(link_channels, index), message, NULL_KEY);
index -= stride;
}while(index > 0);
}
}

set_one(list args)
{
vector color = <0,0,0>;
string channel = llToLower(llList2String(args, 0));
// Handle a common typo gracefully
if(llList2String(args, 1) != "color";)
args = llListInsertList(args, ["color"], 1);

if(llGetListLength(args) == 3)
{
color = parse_named_color(llList2String(args, 2));
}
else if(llGetListLength(args) >= 5)
{
color = <llList2Float(args, 2), llList2Float(args, 3), llList2Float(args, 4)>;
}
if(color == <-1, -1, -1>;)
{
llOwnerSay("Unable to find color";);
}
else
{
llOwnerSay("Setting color of " + channel + " to: " + (string) color);
integer index = llGetListLength(link_channels) - 1;
integer stride = 2;
string message = "color " + (string) color.x + " " + (string) color.y + " " + (string) color.z;
integer found = FALSE;
do
{
if(llList2String(link_channels, index - 1) == channel)
{
llMessageLinked(LINK_SET, llList2Integer(link_channels, index), message, NULL_KEY);
found = TRUE;
}
index -= stride;
}while(!found && index > 0);
if(!found) llOwnerSay("Didn't find a " + channel + "to change.";);
}
}

default
{
listen( integer channel, string name, key id, string message )
{
list args = llParseString2List(message, [" "],[]);
if(llList2String(args, 0) == "color";)
{
set_all(args);
}
else
{
set_one(args);
}
}

touch_start(integer num_detected)
{
if(llDetectedKey(0) == llGetOwner()){
llSetTimerEvent(15);
activate();
}
}

timer()
{
deactivate();
llSetTimerEvent(0);
}
}
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
02-04-2009 17:08
Yeah, it works the same way.. using the textures' keys rather than vectors, obviously. What problem are you having?
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
02-04-2009 17:47
Just scimmed the script, make sure though that instead of casting, where the script puts the vector into color, that it's a string.
dave2bwhipped Ansar
Registered User
Join date: 3 Oct 2008
Posts: 17
02-05-2009 10:01
From: Innula Zenovka
Yeah, it works the same way.. using the textures' keys rather than vectors, obviously. What problem are you having?


So basically I need to change all thens referencing the color vector?
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
02-05-2009 10:29
From: dave2bwhipped Ansar
So basically I need to change all thens referencing the color vector?
That's the idea.. it works in just the same way, so if you feed it the textures' uuids rather than the colours' vectors you should be ok.
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
02-05-2009 12:53
Also forgot, instead of llSetColor, you need to use llSetTexture..... if your not familiar with the function calls, they take the same arguments, except one is vector, and the other is a string.

llSetColor(vector color, integer side)

llSetTexture(string texture, integer side)

and you can pass a key into the texture string, since a key is a special subset of strings.