Jump to content

cycle through a list with repeated mouse clicks


Cloud Aycliffe
 Share

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

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

Recommended Posts

hello,  I'm looking for a small example of a script that would return the value of each element in a list with each mouse click until the elements are exhausted.  It seems I cannot formulate a search query that brings me back such an example.  any advice appreciated.

example:

 list MyList = ["abc", "def", "ghi", "jkl", "lmn", "opq"]

click the prim once
output:abc
click it again
output:def
click it again
output:ghi
click it again
output:jkl
etc...

 

 

 

Link to comment
Share on other sites

When looping through lists like this, I find the the modulo operator, %, very handy.   It gives the remainder after one integer is divided by another.

So, if you have one integer,variable -- call it  iMax --  to hold the length of  MyList, and another integer variable, iCounter, which increases by one each time you click the prim, then iCounter%iMax is going to return a repeating series of numbers, 0 to 5 (since your list has 6 entries).

You can then feed the result to llList2String(MyList, n) to return the list entries in sequence.     After reaching the final entry, it will start over.

 

 

  • Like 1
Link to comment
Share on other sites

I want to do something like:

 

default
{
    state_entry()
    {
        list MyList = ["abc", "def", "ghi", "jkl", "lmn", "opq"];
        integer i;
        integer length = llGetListLength(MyList);
    do
    {
        touch_start(integer total_number)
        {   
       
            llOwnerSay(llList2String(MyList, i));
            
        }
    }
    while (++i < length);
}

However this only results in syntax error (with no explanation of what syntax is wrong)  I really do feel that I am fundamentally going about this wrong but it seems i'm struggling with finding any guidance. 

Link to comment
Share on other sites

You are trying to write a mildly difficult script before you have mastered the basics of LSL.  Your smartest move right now is to take some time to work through tutorials and become familiar with the structure of LSL.  Then take entity's advice and study the behavior of lists and finally, take Innula's advice about how to construct a repeating loop.

Link to comment
Share on other sites

  • 2 weeks later...


Cloud Aycliffe wrote:

do something like:

 


list MyList = ["abc", "def", "ghi", "jkl", "lmn", "opq"];integer i;integer length;default{	state_entry()	{		i = 0;   		length = llGetListLength(MyList);	}	touch_end(integer n)	{				llSay(0, llList2String(MyList, i));		i = (i++) % length;			}}
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1717 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...