Jump to content

Help with Script using Time


8bitBiologist
 Share

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

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

Recommended Posts

Hey guys!

I am working on a script for an activity I am going to use in class. The activity involves students trying to click on a prim with a plant texture. Blocking their path are these dancing clouds. It represents the amount of sun the plants are getting and the students are trying to click on the plants as much as they can.

I have a script that will keep track of the times the student has clicked the prim and it displays a text saying that they have managed to give the plant so many kilocalories of energy. However, I need to simulate how some energy is lost as heat. I would like to add to the script a bit that basically has 1 taken from total counters every 5 seconds.

 

Here is the script;

// Doc: count the current touches

integer count = 0;

update() {
llSetText("Energy Absorbed = "+(string) count+" kilocalories", <1,1,1>, 1.0);
}

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

state_entry() {
update();
}

touch_end(integer p) {
count = count+p;
update();
}
}

 

It is less important but I would be a nice visual if I could get the number of counters reflect as amount of Glow from the prim somehow so the plants would get brighter with more clicks but at the same time, get dimmer if they lose too much energy.

 

Thank you in advance for your help!

Link to comment
Share on other sites

If I were you, I'd begin by getting rid of the state_entry and on_rez events, which are not doing much useful for you. Once you have run the script even one time, the hover text will be a permanent feature of the prim, so there's really no need to regenerate it each time you start the script. That leaves you with a simpler starting script, which can be rewritten as

integer count;default{    touch_end (integer num)    {        llSetText("Energy Absorbed = "+(string) (++count)+" kilocalories", <1,1,1>, 1.0);    }}

 Now, you want a timer that fires every 5 seconds but is only triggered the first time that a student clicks on it and isn't restarted with each click.  And you want that timer to reduce the variable count by 1 each time it fires, without going below zero.  So ...

integer count;default{    touch_end (integer num)    {        if (count == 0)        {            llSetTimerEvent(5.0);        }        llSetText("Energy Absorbed = "+(string) (++count)+" kilocalories", <1,1,1>, 1.0);    }    timer()    {        if (count > 0)        {            llSetText("Energy Absorbed = "+(string) (--count)+" kilocalories", <1,1,1>, 1.0);        }        else        {            llSetTimerEvent(0.0);        }    }           }

 The timer will simply shut off when count has reached zero, but of course will be restarted if students keep clicking.  That means that the script effectively decays to doing nothing at all if you leave it alone for a while.  No need for a restart switch.

If I were you, I'd avoid glow like the plague.  It will make your plant look radioactive once the setting is much over 0.05.  Instead, you could simply adjust overall brightness by starting with your color set at, say, <0.5,0.5,0.5> and then changing it by some small value like <0.02,0.02,0.02> each time count changes. So ...

integer count;default{    touch_end (integer num)    {        if (count == 0)        {            llSetTimerEvent(5.0);        }        llSetText("Energy Absorbed = "+(string) (++count)+" kilocalories", <1,1,1>, 1.0);        llSetColor(<0.5,0.5,0.5> + <0.02,0.02,0.02>*count,ALL_SIDES);    }    timer()    {        if (count > 0)        {            llSetText("Energy Absorbed = "+(string) (--count)+" kilocalories", <1,1,1>, 1.0);            llSetColor(<0.5,0.5,0.5> + <0.02,0.02,0.02>*count,ALL_SIDES);        }        else        {            llSetTimerEvent(0.0);        }    }           }

 Mess with the amount of integral change until it looks right.  Remember that if you are applying color to a textured prim, the color will be added to the colors in the texture itself, so all you're doing is adding or subtracting a little gray at each step from your green leaves.

Before you go much farther, I suggest spending some time with basic LSL tutorials >>> http://wiki.secondlife.com/wiki/LSL_Tutorial

 

 

 

Link to comment
Share on other sites

Thank you so much! The on_rez was there because the entire thing is part of a linkset that is in a holodeck. We will have dozens of these activities that the kids interact with then derezz when they are done. Would I still need it since that is the case?

Link to comment
Share on other sites

Scripting is an exercise in applied logic. Ask yourself why you want to reset the script.  What will happen if you don't? If you can think of a good reason to reset the script when it is rezzed, do it. I can't think of one, but I don't see the big picture that you do.

Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...