In this short post we will try to create a simple counter .
The counters can be used hundreds of times: just think of a contest, a scorer, a timer, a time bomb, a rental or a hit counter box (most common uses and more "observable").
counters can be made to be shown to the "public" (examples above), or even internal counters used as indicators to the script:
example we could say to our cube: as soon as you move 10 meters, turn left .. you walk another 10 meters and stopped . The counter counts the meters one at a time, and when it equals 10, performs the next action. Immediately after
action then, the counter increases (or decreases) the value of a magnitude determined by us.
Let's take a practical example, and in the next little lesson we will see how to create a little hit counter, with long list of names! It may be useful for your land, your shop / business or home.
Let's say we want to create an object that starts counting from 0 to 25, and 25 came to say or do something
write something like this:
////------------ --- begin script ----------- /////
integer counter; / / define global variables as
default
{
state_entry () {
counter = 0; / / reset the counter}
touch_start (integer TOTAL_NUMBER) {
llSetTimerEvent (1); / / execute the timer event every second
}
timer () {
counter + +; / / increases by a drive the counter
llSay (0, (string ) counter);
if (counter == 25) {
llSay ( 0, "I stop and I reset to zero");
llSetTimerEvent (0);
counter = 0; / / reset the counter}
}}
/////---- end script / / /
What happens? Very trivial ... to touch the script will start a timer that increments the counter value every second ... soon as it arrives at 25, the timer stops and resets, in order to be clicked again.
Countdown!
Now that there is a clear logic of the operation, we make two small changes ..
-We will ensure that the account is down
-representation no longer in local chat (which can be annoying), but in a floating text on the same prim.
This time, the counter will start from the number 25, and will decrease the value to 0, in which case our action within the condition IF (in this case we write a simple red text "BOOM"))
////--------------- begin script ----------- /////
integer counter;
default {
state_entry () {
counter = 25; / / start number counter
}
touch_start (integer TOTAL_NUMBER) {
llSetTimerEvent (1);
} timer () {
llSetText (( string) counter, \u0026lt;0,1,0>, 1); / / floating text
counter -; / / decrements a 'unit
if(contatore ==0)
{
ll S etText ("BOOM",<1,0,0>,1);
llSetTimerEvent (0);
contatore=25; / / Fill the meter to 25
}}}
/////---- end script / / /
Practice, adding some other text string in the state entry (example: click here to start the timer) or within the same timer event (eg "Time left:-counter-value") and changing the actions inside the IF condition.
In the next lesson we will create a very simple hit counter script, and reset with the list:)
Stay tuned!
0 comments:
Post a Comment