Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Requesting help/advice/pointer - Scripting newbie attempt

Dragon Muir
Registered User
Join date: 25 Jun 2005
Posts: 60
01-24-2006 22:19
I am probably making myself look really stupid, but I don’t have any scripting friends, so I have no one to ask dumb questions once in a while. Below is a script I attempted to make with my vague noobish understanding of scripting, which as you will see is… perhaps very lacking?

I was attempting to make a script that would cycle through red, orange, yellow, green, blue, purple, and then back to red very fluidly. A Rainbow basically. So that I could add this function (If that is what it is called) to a particle script.

I am obviously doing something very wrong, and missing fundamental basics I simply do not see. If you can point me in the right direction, or point out the basics I am missing or blatant errors in my attempt it would help me out a lot.

Thank you very much for whomever decides to be so gracious enough to help me our or point out my terrible misuse of the language.

Requesting help/advice/pointer - Scripting newbie attempt

I am probably making myself look really stupid, but I don’t have any scripting friends, so I have no one to ask dumb questions once in a while. Below is a script I attempted to make with my vague noobish understanding of scripting, which as you will see is… perhaps very lacking?

I was attempting to make a script that would cycle through red, orange, yellow, green, blue, purple, and then back to red very fluidly. A Rainbow basically. So that I could add this function (If that is what it is called) to a particle script.

I am obviously doing something very wrong, and missing fundamental basics I simply do not see. If you can point me in the right direction, or point out the basics I am missing or blatant errors in my attempt it would help me out a lot.

Thank you very much for whomever decides to be so gracious enough to help me our or point out my terrible misuse of the language.

One last thing, The error messages ware added in the hopes it might shed some light on what I might or might not be wrong, but the error message output basically tells me there is something seriously wrong. Hehe.


float red = 1;
float green = 0;
float blue = 0;

rainbow()
{
if (red == 1){
if (green == 1)
{
if (blue == 1)
{
llSay(0, "Error1";);
}
if (blue < 1)
{
llSay(0, "Error2";);
}
if (blue == 0)
{
red = red - .01;
}
}
if (green < 1)
{
if (blue == 1)
{
llSay(0, "Error3";);
}
if (blue == 1)
{
llSay(0, "Error4";);
}
if (blue == 0)
{
green = green - .01;
}
}
if (green == 0)
{
if (blue == 1)
{

}
if (blue < 1)
{
llSay(0, "Error5";);
}
if (blue == 0)
{
green = green + .01;
}
}
}
if (red == 0){
if (green == 1){
if (blue == 1)
{
llSay(0, "Error6";);
}
if (blue < 1)
{
green = green + .01;
}
if (blue == 0)
{
blue = blue + .01;
}
}
if (green < 1){
if (blue == 1)
{
llSay(0, "Error7";);
}
if (blue < 1)
{
llSay(0, "Error8";);
}
if (blue == 0)
{
blue = blue + .01;
}
}
if (green == 0){
if (blue == 1)
{
red = red + .01;
}
if (blue < 1)
{
red = red + .01;
}
if (blue == 0)
{
red = red + .01;
}
}
}
if (red < 1){
if (green == 1){
if (blue == 1)
{
llSay(0, "Error9";);
}
if (blue < 1)
{
llSay(0, "Error10";);
}
if (blue == 0)
{
red = red - .01;
}
}
if (green < 1){
if (blue == 1)
{
llSay(0, "Error11";);
}
if (blue < 1)
{
llSay(0, "Error12";);
}
if (blue == 0)
{
llSay(0, "Error";);
}
}
if (green == 0){
if (blue == 1)
{
llSay(0, "Error13";);
}
if (blue < 1)
{
llSay(0, "Error14";);
}
if (blue == 0)
{
llSay(0, "Error15";);
}
}
}
}
Aliasi Stonebender
Return of Catbread
Join date: 30 Jan 2005
Posts: 1,858
01-24-2006 22:56
firstly use the {php} {/php} (just use square brackets instead of curlies) to show your code nicely. Example:

CODE

float red = 1;
float green = 0;
float blue = 0;

rainbow()
{
if (red == 1){
if (green == 1)
{
if (blue == 1)
{
llSay(0, "Error1");
}
if (blue < 1)
{
llSay(0, "Error2");
}
if (blue == 0)
{
red = red - .01;
}


Secondly, that looks a lot more complicated than you really need. we've got loops for a REASON! :)

I'd try something like this. (pretend the llSetColor line is however you make the particle system, with the color vector in the appropriate spot. I can show you how if you catch me online sometime. Do keep in mind having something like this constantly updating will contribute to lag. This also probably isn't quite the best way to do it, but it's late and it's still good to demonstrate the point.)

CODE

vector coloring = <1, 0, 0>;

for (coloring.y = 0; coloring.y < 1; coloring.y += 0.1) //go from red to yellow
{
llSetColor(coloring, ALL_SIDES);
}

for (coloring.x = 1; coloring.x > 0; coloring.x -= 0.1) //go from yellow to green
{
llSetColor(coloring, ALL_SIDES);
}

for (coloring.z = 0; coloring.z < 1; coloring.z += 0.1) //go from green to cyan
{
llSetColor(coloring, ALL_SIDES);
}

for (coloring.y = 1; coloring.y > 0; coloring.y -= 0.1) //go from cyan to blue
{
llSetColor(coloring, ALL_SIDES);
}

for (coloring.x = 0; coloring.x < 1; coloring.x += 0.1) //go from blue to purple
{
llSetColor(coloring, ALL_SIDES);
}

for (coloring.z = 1; coloring.z > 0; coloring.z -= 0.1) //go from purple to red
{
llSetColor(coloring, ALL_SIDES);
}
_____________________
Red Mary says, softly, “How a man grows aggressive when his enemy displays propriety. He thinks: I will use this good behavior to enforce my advantage over her. Is it any wonder people hold good behavior in such disregard?”
Anything Surplus Home to the "Nuke the Crap Out of..." series of games and other stuff
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
01-25-2006 04:34
You might find this helpful: it generates cycling rainbow colour vectors. Pass it a value from 0-59 to represent where in the cycle you want to be (0 for red at the start, 59 for blue at the end).

CODE

vector rainbow(integer pos) {
if (pos < 10) return <1.0,((pos)*0.1),0.0>;
if (pos < 20) return <(1.0-((pos - 10)*0.1)),1.0,0.0>;
if (pos < 30) return <0.0,1.0,((pos - 20)*0.1)>;
if (pos < 40) return <0.0,1.0-((pos - 30)*0.1),1.0>;
if (pos < 50) return <((pos - 40)*0.1),0.0,1.0>;
if (pos < 60) return <1.0,0.00,1.0-((pos - 50)*0.1)>;
return <0.0,0.0,0.0>;
}
Aliasi Stonebender
Return of Catbread
Join date: 30 Jan 2005
Posts: 1,858
01-25-2006 08:04
Heh, see what I mean? :)
_____________________
Red Mary says, softly, “How a man grows aggressive when his enemy displays propriety. He thinks: I will use this good behavior to enforce my advantage over her. Is it any wonder people hold good behavior in such disregard?”
Anything Surplus Home to the "Nuke the Crap Out of..." series of games and other stuff
Aliasi Stonebender
Return of Catbread
Join date: 30 Jan 2005
Posts: 1,858
01-25-2006 11:29
and, just to spell it out - here's how to take that function and make it duplicate that sloppy code I wrote at 2 am local time. :)

CODE

vector rainbow(integer pos) {
if (pos < 10) return <1.0,((pos)*0.1),0.0>;
if (pos < 20) return <(1.0-((pos - 10)*0.1)),1.0,0.0>;
if (pos < 30) return <0.0,1.0,((pos - 20)*0.1)>;
if (pos < 40) return <0.0,1.0-((pos - 30)*0.1),1.0>;
if (pos < 50) return <((pos - 40)*0.1),0.0,1.0>;
if (pos < 60) return <1.0,0.00,1.0-((pos - 50)*0.1)>;
return <0.0,0.0,0.0>;
}

default
{

touch_start(integer total_number)
{
integer x;
for (x = 0; x <= 59; x++)
{
llSetColor(rainbow(x), ALL_SIDES);
llSleep(0.1);
}

}
}
_____________________
Red Mary says, softly, “How a man grows aggressive when his enemy displays propriety. He thinks: I will use this good behavior to enforce my advantage over her. Is it any wonder people hold good behavior in such disregard?”
Anything Surplus Home to the "Nuke the Crap Out of..." series of games and other stuff