Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Color change via lists

Stinky Queso
Second Life Resident
Join date: 29 Nov 2004
Posts: 53
12-09-2004 23:42
I'm making a color changing particle script, which many people have done, but I cannot seem to make this work. I'm basically listening for smoke color X on channel 5, and then pulling a vector from a list and assigning it to a variable based on the substring after "smoke color." for some reason, this script always produces black smoke, and I know it has nothing to do with the particlesystem part of the script.

There is probably a way to do this better, but I'm still getting used to thinking in LSL.

Any help is appreciated

CODE:

edit: try shoving this into a new script and type /5 smoke color 2
it whispers the vector, but its always <0,0,0>

CODE
vector color;
list colores = [<1, 1, 1>,<1, 0, 0>,<1, 1, 0>,<1, 0, 1>,<0, 1, 1>,<0, 1, 0>,<0, 0, 1>];
default
{
on_rez(integer lksdj)
{
llResetScript();
}
state_entry()
{
llListen( 5, "", llGetOwner(), "" ) ;
//sound
}
listen( integer channel, string name, key id, string message )
{





string result = llGetSubString(message, 0, 10);
if(result == "smoke color")
{
string end = llGetSubString(message, 11, llStringLength(message) - 1);

if(end == "1")
{
color = llList2Vector(colores, 0);
}

if(end == "2")
{
color = llList2Vector(colores, 1);
llWhisper(0, (string)color);
}

if(end == "3")
{
color = llList2Vector(colores, 2);
}

if(end == "4")
{
color = llList2Vector(colores, 3);
}

if(end == "5")
{
color = llList2Vector(colores, 4);
}

if(end == "6")
{
color = llList2Vector(colores, 5);
}

if(end == "7")
{
color = llList2Vector(colores, 6);
}

llWhisper(0, (string)color);
}
Pete Fats
Geek
Join date: 18 Apr 2003
Posts: 648
12-10-2004 00:07
I have had some really weird results with llList2Vector as well. The work around that I have used in the past, is to pack the list with strings, and then typecast them when I need to used them:

list vectors = ["<1,1,1>", "<2,2,2>"];

llSetColor((vector)llList2String(vectors, 0), ALL_SIDES);

Give that a try and I think it will fix it.

BTW - You win the random name of the day award! :D
_____________________
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
12-10-2004 01:52
Your script works fine, your inputting the data wrong, if you analyze what is in each string. I am sure you will discover your problem.

hint, add this line to your code
llSay ( 0, "The Value of string 'end is : '" + end + "'" );



ot, you said your using this code to change colors. Is your goal to be able to do some thing like say "smoke brown", "smoke white" ?

it not, and you really intented to use numbers (smoke 1, smoke 2) , then there is an easyer way to do what you want. You could convert the last input as an int, and do color = llList2Vecotor ( colores , end ). Witch would save you from that long if else statement.

Witch remineds me. The value of end can not be 1 or 3 at the same time right? Right now you have 8 or 9 if statments after each if, each one has to check the value of end. In this case you should be using an if else system
ie:

if ( end == "1" )
{
color = llList2Vector(colores, 0);
}
else if ( end == "2" )
{
color = llList2Vector(colores, 1);
}

this way if end == "1" it dose not check if end == "2". It will only check if end == "2" if end == "1" returns faluse. This will make your program faster, and more efficient.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
12-10-2004 03:47
FYI if you pack them in as vectors then you can pull them out as vectors *but* since they are mad of floats there may be some data loss (floats only show 5 decimal places).

If your anal retentive about storing data in strings then it's best to use a function to convert your float to Scientific notation.

Linky
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Stinky Queso
Second Life Resident
Join date: 29 Nov 2004
Posts: 53
12-10-2004 16:50
Pete: packaging as a string and typecasting to vector does not work, thanks for the suggestion. I'm happy you find my name amusing.

Kurt: my string manipulation is fine, but for some reason the variable color is never changing. at all. Even though I assign it a value from the list, it doesnt change from 0,0,0. thanks for the else if tip, saved my life.

Strife: The vectors are fine, I don't really need floats.

thanks for the input, but it still doesn't work. Is there an easier way to do this?

EDIT!! MY STRING MANIP WAS SCREWEY!! THANK YOU KURT
it works now.

You guys are so helpful
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
12-10-2004 18:18
One of my programing teachers always said, garbage in garbage out. So I always test in and out. Soon as I saw the 11, but only because my programing teacher in high school beat it into my head. :) I am so glad you figured it out. I was really tempted to tell you, but some times people just need a push. I hope you learned some thing valuable by figuring it out on your own. :D


If your ever need help with your script, you can im me.
Rico Plisskin
Registered User
Join date: 17 Feb 2005
Posts: 104
04-16-2005 07:36
lol...could somebody re-make that script in english for my noobiness. I been lookin for a color changing particle script and i was getting ready to use this one but then saw all the replies to fix the first script which made no sense to me. Thank You
gene Poole
"Foolish humans!"
Join date: 16 Jun 2004
Posts: 324
04-16-2005 10:10
How about this? Untested... might work, though:
CODE

list COLORS = [<1, 1, 1>, <1, 0, 0>, <1, 1, 0>, <1, 0, 1>, <0, 1, 1>, <0, 1, 0>, <0, 0, 1>]; // add more if you like (there's a limit, check the wiki)
string CMD = "color"; // change this to use a different command

default
{
on_rez(integer startVal)
{
llResetScript();
}

state_entry()
{
llListen(1, "", llGetOwner(), ""); // using channel 1
}

listen(integer channel, string name, key id, string message)
{
if (llStringLength(message) < (llStringLength(CMD) + 2))
return; // if we don't even have enough characters to constitute a full command, ignore the message
string cmd = llGetSubString(message, 0, llGetStringLength(CMD) - 1);
if (llToLower(cmd) == llToLower(CMD)) // ignore case
{
vector color;
string indexStr = llGetSubString(message, llGetStringLength(CMD) + 1, llStringLength(message) - 1); // skip the command and first space (the client replaces runs of whitespace with a single space)
string index = (integer)indexStr; // convert to ordinal
if (index > llGetListLength(COLORS))
return; // ignore color indices that are out of range
index--; // decrement by one, for list indices are zero-based
vector color = llList2Vector(COLORS, index);

// now, do something with the color vector; we'll just report it for now
llWhisper(0, "color vector is: " + (string)color);
}
}
}
Rico Plisskin
Registered User
Join date: 17 Feb 2005
Posts: 104
04-16-2005 11:38
vector color = llList2Vector(COLORS, index);

(28, 52) : ERROR : Name previously declared within scope



llWhisper(0, "color vector is: " + (string)color);

(31, 9) : ERROR : Syntax error
Talena Wallaby
Registered User
Join date: 20 Mar 2005
Posts: 19
04-16-2005 13:00
Fixed errors in the above script so that it compiles and works. Useage is /1 color #, where # is 0-6.

CODE
list COLORS = [<1, 1, 1>, <1, 0, 0>, <1, 1, 0>, <1, 0, 1>, <0, 1, 1>, <0, 1, 0>, <0, 0, 1>]; // add more if you like (there's a limit, check the wiki)
string CMD = "color"; // change this to use a different command

default
{
on_rez(integer startVal)
{
llResetScript();
}

state_entry()
{
llListen(1, "", llGetOwner(), ""); // using channel 1
}

listen(integer channel, string name, key id, string message)
{
if (llStringLength(message) < (llStringLength(CMD) + 2))
return; // if we don't even have enough characters to constitute a full command, ignore the message

string cmd = llGetSubString(message, 0, llStringLength(CMD) - 1);

if (llToLower(cmd) == llToLower(CMD)) // ignore case
{
string indexStr = llGetSubString(message, llStringLength(CMD) + 1, llStringLength(message) - 1); // skip the command and first space (the client replaces runs of whitespace with a single space)

integer index = (integer)indexStr; // convert to ordinal
if (index > llGetListLength(COLORS))
return; // ignore color indices that are out of range

index--; // decrement by one, for list indices are zero-based
vector color = llList2Vector(COLORS, index);

// now, do something with the color vector; we'll just report it for now
llWhisper(0, "color vector is: " + (string)color);
}
}
}
Rico Plisskin
Registered User
Join date: 17 Feb 2005
Posts: 104
04-16-2005 17:02
The commands and script seems to work but dont see any change in the particles. I am using Ama's/Jopsy's Particle Script 0.4J...and made a seperate script for color change.
lmho Impfondo
Registered User
Join date: 7 Apr 2005
Posts: 31
04-17-2005 10:52
From: Rico Plisskin
The commands and script seems to work but dont see any change in the particles. I am using Ama's/Jopsy's Particle Script 0.4J...and made a seperate script for color change.


if you want an instant particle change when you issue a command, create an empty function (no return) with your particle script in it. Either pass values to the function or create globals that determine the particle differences. Then when the command is issued simply call the particle function with the updated variables (ie color vectors and such). Oh yeah, and get a really basic particle script, it helps. IM me in game and I can shove one on ya.