Jump to content

strided list trouble


Tabris Daxter
 Share

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

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

Recommended Posts

hey all,

 

i'm having some problems with getting strided lists to work.

what i want is record

0 >> -1 stride of 3 for top menu.

1 >> -1 stride of 3 for level 2 menu

2 >> -1 stride of 3 for final menu.

the list is made up of the names of notecards in the format of "scene.city.office" & "scene.beach.palm tree"

 

code follows

list NCnames;
scene_lst()
{
    NCnames = [];
    integer numNC = llGetInventoryNumber(INVENTORY_NOTECARD);
    integer x = 0;
    while (x < numNC)
    {
        NCnames += llParseString2List(llGetInventoryName(INVENTORY_NOTECARD,x++),["."],[]);
    }
    
}
    

default
{
    state_entry()
    {
       
    }
    
    touch_start(integer badtouch)
    {
        scene_lst();
        integer lstlen = llGetListLength(NCnames);
        integer i = 0;
        list result_a = llList2ListStrided(NCnames,0,-1,2);
        list result_b = llList2ListStrided(NCnames,2,-1,3);
        list result_c = llList2ListStrided(NCnames,3,-1,3);
        llSay(0,llDumpList2String(result_a,"++"));
        llSay(0,llDumpList2String(result_b,"++"));
        llSay(0,llDumpList2String(result_c,"++"));
        //while (i < lstlen)
        //{
        //    llSay(0,(string)i + " " + llList2String(NCnames,i));
        //    i++;
        //}
    }
}

 current output in chat

scene++Palm Tree++beach++scene++back alley
NC test: scene++scene
NC test: scene++scene

i'm trying to get this working first before working on the dialog bit

(need something stronger than REDBULL, DR PEPPER & VODKA for that :matte-motes-big-grin:)

ty in advance

 

EDIT:

do i even need to use strided lists? am i over complicating it?

Link to comment
Share on other sites

Your parameters for llList2ListStrided() do not make sense to me
In my book they should be:

list result_a = llList2ListStrided(NCnames,0,-1,3);list result_b = llList2ListStrided(NCnames,1,-1,3);list result_c = llList2ListStrided(NCnames,2,-1,3);

 Reference

You can use three separate synchronized list instead of one strided
You only need to keep synchronism, add and delete elements synchronized

Link to comment
Share on other sites

ty Dora.

so basically i have to do this

 

So, to get every second element...
llList2ListStrided(llDeleteSubList(src, 0, 0), 0, -1, 2));
and to get every third element...
llList2ListStrided(llDeleteSubList(src, 0, 1), 0, -1, 3));

yay for not working as intended.

 

EDIT:

forgot

reference to

list result_a = llList2ListStrided(NCnames,0,-1,3);list result_b = llList2ListStrided(NCnames,2,-1,3);list result_c = llList2ListStrided(NCnames,3,-1,3);

i was playing with the numbers trying to the the damn thig to work

Link to comment
Share on other sites


Tabris Daxter wrote:

 

do i even need to use strided lists? am i over complicating it?

You never need to use strided lists. It's a matter of personal preference, but I avoid strided lists almost completely.  I have rarely found a situation in which a strided list offers an advantage over running a set of parallel simple lists.  IMO, strided lists are a clumsy substitute for having real arrays.  If I work with simple lists and keep them indexed the same way, I find that I have more freedom to manipulate individual variables and to add and remove them as my conceptual model changes.  The biggest advantage -- for one who easily forgets her way and can use all the signposts she can create -- is that I can give individual lists distinctive names.  It's SO much easier to remember that list gNames contains avatar names and list gUUIDs contains avatar keys than it is to remember which stride of list gAvatarData is which.  If I come back to a script two months later, I can tell at a glance where things are.

Link to comment
Share on other sites

There is one place where a strided list has a huge advantage and that is sorting with the built-in LSL function.
All elements in the stride will follow the sorting of the first element in the stride.
To do the same thing with parallel lists you have to write your own sort which isn't trivial and take more time and code than the built-in single function sort.

Apart from this I don't see any advantages neither:smileytongue:

Link to comment
Share on other sites

for your use case, parallel lists are probably optimal since you are not doing any sorting.

that method means less work when you want to insert one into the dialog since you won't have to break it down each time, and you can still easily search all of them in the listen.

 

in general parrallel is much better at searching than strides and much easier to insert, as well as having less overhead during use, strides excel at speedy input/output dumps, sorting (though only on the first element)., and adjustable record depth (which see's little use in LSL, though with parallel lists you have to plan ahead on hard limits, strided lists only have the hard bound of being able to duplicate the list in memory)

Link to comment
Share on other sites

OK here is my current code. I've gone with the parallel lists but now i'm having trouble with the dialog.

list NCnames;list type;list catagory;list scenename;list btnlvl1 = ["scene","on","off"];key toucherID;integer diagchan;integer Ldiag;scene_lst(){    NCnames = [];    integer numNC = llGetInventoryNumber(INVENTORY_NOTECARD);    integer x = 0;    while (x < numNC)    {        NCnames += llParseString2List(llGetInventoryName(INVENTORY_NOTECARD,x++),["."],[]);    }    /*type = llList2ListStrided(NCnames, 0, -1, 3);    catagory = llList2ListStrided(llDeleteSubList(NCnames, 0, 0), 0, -1, 3);    scenename = llList2ListStrided(llDeleteSubList(NCnames, 0, 1), 0, -1, 3);*/    integer NClstlen = llGetListLength(NCnames);    integer i = 0;    while (i < NClstlen)    {        type += llList2String(NCnames,i++);        catagory += llList2String(NCnames,i++);        scenename += llList2String(NCnames,i++);    }}list ListUnique( list lAll ) {    integer i;    list lFiltered = llList2List(lAll, 0, 0);    integer iAll = llGetListLength( lAll );    for (i = 1; i < iAll; ++i) {        if ( llListFindList(lFiltered, llList2List(lAll, i, i) ) == -1 ) {            lFiltered += llList2List(lAll, i, i);        }    }    return lFiltered;}    default{    state_entry()    {       diagchan = -1000;       Ldiag = llListen(diagchan,"","","");       scene_lst();    }        touch_start(integer badtouch)    {        toucherID = llDetectedKey(0);        llDialog(toucherID,"HI ALL",btnlvl1,diagchan);        llSetTimerEvent(30);                          }        listen(integer chan, string name, key id, string msg)    {        if (chan == diagchan)        {            integer menulvl1 = llListFindList(btnlvl1,[msg]);            integer menulvl2 = llListFindList(catagory,[msg]);            integer menulvl3 = llListFindList(scenename,[msg]);            if (menulvl1 != -1)            {                                if (llList2String(btnlvl1, menulvl1) == msg)                {                       llDialog(toucherID,llList2String(btnlvl1, menulvl1),ListUnique(catagory),diagchan);                    //llDialog(toucherID,llList2String(btnlvl1, menulvl1),catagory,diagchan);                    llSetTimerEvent(30);                }                else if (llList2String(catagory, menulvl2) == msg) 
{
llDialog(toucherID,llList2String(catagory, menulvl2),ListUnique(scenename),diagchan);
 llSay(0,llList2String(scenename,menulvl3)); llSetTimerEvent(30);
}
} } } timer() { llListenRemove(Ldiag); }}

 the part bolded is meant to bring up the last level menu and allow for the notecard to be chosen.

 

EDIT:

the formatting borked

Link to comment
Share on other sites

the first level is the only command that will be the same all others can change dependant on the names of the notecards.

the format of the notecard names is type.catagory.name.

so scene >> beach >> water fall, will open the notecard named "scene.beach.water fall"

 

this test

else if (llList2String(catagory, menulvl2) == msg)

(anything after this fails to fire or something)

is supposed to test if the catagory equals the message recieved and then bring up the level 3 (name) dialog

Link to comment
Share on other sites

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