Jump to content

Please kindly help to add touch start and end early to this script please


kiki Chaika
 Share

You are about to reply to a thread that has been inactive for 2780 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

hi everyone, I really do not know much about scripting, but I am trying to learn and research as much as I can May I ask how to add a touch to start (or restart) and touch again to end early to this script please? it is a particle emitter script. When I touch it now, it ends early but when I touch it again, it does not restart... what is wrong? Please help and thanks! Thank y you very much in advance.

 

 

// DECLARATION ==============================
string Texture;
integer Interpolate_Scale;
vector Start_Scale;
vector End_Scale;
integer Interpolate_Colour;
vector Start_Colour;
vector End_Colour;
float Start_Alpha;
float End_Alpha;
integer Emissive;
float Age;
float Rate;
integer Count;
float Life;
integer Pattern;
float Radius;
float Begin_Angle;
float End_Angle;
vector Omega;
integer Follow_Source;
integer Follow_Velocity;
integer Wind;
integer Bounce;
float Minimum_Speed;
float Maximum_Speed;
vector Acceleration;
integer Target;
key Target_Key;


// BASIC FUNCTION ==============================

Particle_System ()
{
list Parameters =
[
PSYS_PART_FLAGS,
(
(Emissive * PSYS_PART_EMISSIVE_MASK) |
(Bounce * PSYS_PART_BOUNCE_MASK) |
(Interpolate_Colour * PSYS_PART_INTERP_COLOR_MASK) |
(Interpolate_Scale * PSYS_PART_INTERP_SCALE_MASK) |
(Wind * PSYS_PART_WIND_MASK) |
(Follow_Source * PSYS_PART_FOLLOW_SRC_MASK) |
(Follow_Velocity * PSYS_PART_FOLLOW_VELOCITY_MASK) |
(Target * PSYS_PART_TARGET_POS_MASK)
),
PSYS_PART_START_COLOR, Start_Colour,
PSYS_PART_END_COLOR, End_Colour,
PSYS_PART_START_ALPHA, Start_Alpha,
PSYS_PART_END_ALPHA, End_Alpha,
PSYS_PART_START_SCALE, Start_Scale,
PSYS_PART_END_SCALE, End_Scale,
PSYS_SRC_PATTERN, Pattern,
PSYS_SRC_BURST_PART_COUNT, Count,
PSYS_SRC_BURST_RATE, Rate,
PSYS_PART_MAX_AGE, Age,
PSYS_SRC_ACCEL, Acceleration,
PSYS_SRC_BURST_RADIUS, Radius,
PSYS_SRC_BURST_SPEED_MIN, Minimum_Speed,
PSYS_SRC_BURST_SPEED_MAX, Maximum_Speed,
PSYS_SRC_TARGET_KEY, Target_Key,
PSYS_SRC_ANGLE_BEGIN, Begin_Angle,
PSYS_SRC_ANGLE_END, End_Angle,
PSYS_SRC_OMEGA, Omega,
PSYS_SRC_MAX_AGE, Life,
PSYS_SRC_TEXTURE, Texture
];
llParticleSystem (Parameters);
}

// YOUR PARTICLES FUNCTION ==============================

MyParticle (){
Texture = "UUID of the TEXTURE";
Interpolate_Scale = TRUE;
Start_Scale = <0.5,0.5, 0>;
End_Scale = <0.04,0.04, 0>;
Interpolate_Colour = FALSE;
Start_Colour = < 1, 1, 1 >;
End_Colour = < 1, 1, 1 >;
Start_Alpha = 1;
End_Alpha =1;
Emissive = TRUE;
Age = 12.2;
Rate = 0.5;
Count = 1;
Life = 20;
Pattern = PSYS_SRC_PATTERN_ANGLE;
Radius = 0;
Begin_Angle = 0;
End_Angle = 0.7853975;
Omega = < 0, 0, 0 >;
Follow_Source = TRUE;
Follow_Velocity = FALSE;
Wind = TRUE;
Bounce = TRUE;
Minimum_Speed = 1;
Maximum_Speed = 1;
Acceleration = < 0, 0, 0 >;
Target = FALSE;
Target_Key = NULL_KEY;

Particle_System ();
}

// SCRIPT BODY ==============================

default
{

state_entry ()
{
MyParticle ();
}

touch_start (integer i){
llParticleSystem ([]); // Stop the particles
}

}

Link to comment
Share on other sites

The function that starts the particles again in your script is called MyParticles() - you'll need to call that within touch_start in order to restart emission of particles.

You'll probably also want a toggle, setting a variable to 1 or 0 depending on whether the particles should be on or off.

Something like:-

touch_start(integer num_det){    if(showParticles)    {         showParticles = FALSE;         //Also end particles    }    else    {         showParticles = TRUE;         //Also start particles    }}

Remember to use the 'Add Code' button when posting code to the forum. It looks like a </> button at the top of your editor. Makes everything much easier to read!

Good luck. :)

Link to comment
Share on other sites

What's wrong is that you have only told it to stop.  Nothing tells it to start unless you take the clumsy step of resetting the whole script.  You need to master the simple logic of the light switch:

integer gON;default{    touch_start(integer num)    {        gON = !gON;        if (gON)        {            // The switch is ON, so do "on" stuff        }        else        {            // The switch is OFF, so do "off" stuff        }    }}
Link to comment
Share on other sites

All you need to worry about is at the very bottom.  The Script Body.

You will need to add something to say if the particles are on or off. Then, instead of turning the particles on at state entry, do it all in the touch event.

 

// SCRIPT BODY ==============================
integer IsItRunning;
default{

state_entry (){ IsItRunning = FALSE; } touch_start (integer i){
if (IsItRunning){
      llParticleSystem ([]);
      IsItRunning = FALSE;
} else {      MyParticle ();
      IsItRunning = TRUE;
}
}}

Does that make sense?

 

It is not tested and just written in my head so be sure you understand what it is doing before you go plugging it in so you can fix it.  There is a good chance I missed something :)

 

[ETA]

I R 2 s l o w .

 

[ETA 2]
See ?  I had the switch backwards!
It should be fixed now

 

 

Link to comment
Share on other sites

Each of the answers is saying exactly the same thing, showing you how to write a basic toggle switch. Putting it into your script is your job.  This forum is for scripters to share ideas and to learn from each other, not to write each other's scripts.  So to learn, take what we have each showed you and experiment.

You can see that your script already has a touch_start event, and you can see what it does. Our suggestions are all versions of a replacement for what you already have.  The only new thing that you will need to add is a definition of the global integer variable (gON in my version) at the very top of your own script.

Give it a shot.  You can do this.  ;)

Link to comment
Share on other sites

I think the only issue is.... When I click once, it start the script... the script end at a timer... When I click it again it does not do anything (call for stop script function?) I have to click it one more time ... Is there a way where ... if the timer end, it ends.... and once i click it, it will start immediately instead of calling the script to stop running please? Thanks.

Link to comment
Share on other sites

I understand... that is why even I really do not know how to script, I have been trying and it can take me 3 days to figure something out that you guys can do it in 5 sec... believe me, it happened before. I wish there are good books are really good systematic way to learn this instead of picking it bits and pieces from everywhere.

Link to comment
Share on other sites


kiki Chaika wrote:

I understand... that is why even I really do not know how to script, I have been trying and it can take me 3 days to figure something out that you guys can do it in 5 sec... believe me, it happened before. I wish there are good books are really good systematic way to learn this instead of picking it bits and pieces from everywhere.

That's the way learning works.  It's not easy.  None of us could do it in 5 seconds when we started either, but we didn't get where we are by having other people write our scripts for us.  We spent 3 days agonzing over our work, experimenting and picking up bits and pieces from everywhere.  And working through basic tutorials like the ones at http://wiki.secondlife.com/wiki/LSL_Tutorial and, of course, coming to forums like this when we really got stuck.

Now, the extra step that you have just added is a bit more difficult.  You want to add a timer to turn the particles ON and OFF.  In that case, you'll still use the touch_start event to trigger the timer, but now you'll need to do the actual work of turning the particles on and off in a new timer event.  You'll also need to provide a way to disable the touch_start event while the timer is running, so that it doesn't keep restarting the timer.  Again, schematically, you want something that behaves like this:

integer gON;// Ignoring all the stuff until you get to the touch_start eventtouch_start(integer num){    if (gON == FALSE)  // If the switch hasn't been touched yet    {        gON = TRUE;   // Now it has, so set the flag to disable touching it again        llSetTimerEvent(10.0);   /// Or however many seconds you want the timer to run        // Start your particles here    }}timer(){    //Time's up, so ...    llParticleSystem([]);    // Stop the particles    gON = FALSE;   // And enable the touch_start event again    llSetTimerEvent(0.0);  // And turn off the time}    
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2780 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...