Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

creating "counters" in LSL

Aminom Marvin
Registered User
Join date: 31 Dec 2006
Posts: 520
03-14-2007 10:30
Hi, I'm somewhat new to LSL; been scripting for around three months, and slowly adding functions and techniques to my repertoir :) With many things, there's probably several ways of doing this...

How does one make a counter; i.e. a variable that increases when an event is triggered? For example, it would start at variable=0, then a state or event would make it increase so that variable=1, and so on until when variable=5, something happens. Preferably I'd like to know of several ways of doing this :)
Dustin Widget
Script Monkey for hire
Join date: 15 Feb 2006
Posts: 101
03-14-2007 11:00
Well, global variable is probably your best bet. Then just have the increment in your event. Such as:

CODE

integer counter;

default
{
state_entry()
{
counter = 0;
}
touch_start(integer num_touchers)
{
counter++;
if(counter == 5)
{
llOwnerSay("mmmm yes...");
counter = 0;
}
}
}
Aminom Marvin
Registered User
Join date: 31 Dec 2006
Posts: 520
03-14-2007 11:04
Many thanks :) Another basic tool that will be widely useful.