Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

ON/OFF Particle Switch

Soleil Samiam
Registered User
Join date: 17 Mar 2005
Posts: 2
03-20-2005 02:35
Is there a script available to turn particles off and on by clicking on the object?

-Soleil
Fuzzy Duck
Out Of Focus
Join date: 19 Feb 2005
Posts: 48
03-20-2005 04:01
something along the lines of ......

CODE

default()
{
state_entry()
{
state particles_on();

}
}

state particles_on()
{
state_entry()
{
// particles system stuff
}

touch_start(integer touch_num)
{
state particles_off();
}
}

state particles_off()
{
state_entry()
{
llParticleSystem([]);
}

touch_start(integer touch_num)
{
state particles_on();
}
}




Insert your own particle system at "// particles system stuff" and that should do it.
_____________________
Sorin Rubio
Registered User
Join date: 26 Mar 2004
Posts: 8
03-20-2005 04:29
Fuzzy's method will work, but if you want to avoid using state changes:

CODE

UpdateParticles()
{
//Insert particle Params
}
default
{
state_entry()
{
running=TRUE;
UpdateParticles();
}

touch_start(integer num_detected)
{
if (running==TRUE)
{
running=FALSE;
llParticleSystem([]);
}
else
{
running=TRUE;
UpdateParticles();
}
}
}

Fuzzy Duck
Out Of Focus
Join date: 19 Feb 2005
Posts: 48
03-20-2005 05:03
The Wiki says States are a good programming practice ..

From: someone
States vs. Global variables

A state and a set of global variables can serve the same purpose, and each can be expressed in terms of the other. In general, you should prefer the use of states over global variables since states allow you to immediately assume script state without making comparisons. The less comparisons a script makes, the more regular code statements it can run.
_____________________
Sorin Rubio
Registered User
Join date: 26 Mar 2004
Posts: 8
03-20-2005 05:57
Ah, I'll keep that in mind, thank you.
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
03-20-2005 06:26
Eggy was trying to explain the reasons for choosing states over global variables in this thread. I have to admit, I wasn't totally clear on his point, as it didn't seem nearly as important as he was making it out to be. I freely admit that while I certainly know more than most people, I still don't understand anywhere near as much as I'd like to. Fortunately, I eventually figured out what he was getting at, and surprise, surprise, he's right. :)

By comparing Jillian's and Jeffrey's scripts in this thread, we can immediately see the advantages of using states over variables. In Jillian's example, not only must the script check a variable every time it's clicked, it also still processes clicks while it would otherwise be sleeping.

Compare that with Jeffrey's states example, where there's no checking necessary, ever, and the script doesn't even do any processing while it's sleeping. There isn't even a touch_start event in the "wait" state. Both methods accomplish the same task, but Jeffrey's is more efficient.
_____________________
Need scripting help? Visit the LSL Wiki!
Omega Point - Catherine Omega's Blog