Tabris Daxter Posted August 27, 2011 Share Posted August 27, 2011 hey all, i'm having some problems with getting strided lists to work.what i want is record0 >> -1 stride of 3 for top menu.1 >> -1 stride of 3 for level 2 menu2 >> -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 followslist 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 chatscene++Palm Tree++beach++scene++back alleyNC test: scene++sceneNC test: scene++scenei'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 More sharing options...
Dora Gustafson Posted August 27, 2011 Share Posted August 27, 2011 Your parameters for llList2ListStrided() do not make sense to meIn 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 stridedYou only need to keep synchronism, add and delete elements synchronized Link to comment Share on other sites More sharing options...
Tabris Daxter Posted August 27, 2011 Author Share Posted August 27, 2011 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 More sharing options...
Rolig Loon Posted August 27, 2011 Share Posted August 27, 2011 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 More sharing options...
Dora Gustafson Posted August 27, 2011 Share Posted August 27, 2011 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 More sharing options...
Void Singer Posted August 27, 2011 Share Posted August 27, 2011 todo list: write a simplified insertion sort for parallel lists (there's an example of a "most recent" sort and add in my spamless greeter script on my wiki page) Link to comment Share on other sites More sharing options...
Tabris Daxter Posted August 27, 2011 Author Share Posted August 27, 2011 So back to original question. (sort of) this is part 1 in a much larger project. I'm making a nested dialog menu from the names of notecards in the format of "menu1.menu2.menu3" will that work with 3 parallel lists or is 1 strided recomended? Link to comment Share on other sites More sharing options...
Rolig Loon Posted August 27, 2011 Share Posted August 27, 2011 It's entirely a matter of personal preference. Do whatever you are most comfortable with. For me, it's parallel lists, but that's me. Which flavor of ice cream is better: vanilla or chocolate? Link to comment Share on other sites More sharing options...
Void Singer Posted August 28, 2011 Share Posted August 28, 2011 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 More sharing options...
Tabris Daxter Posted August 28, 2011 Author Share Posted August 28, 2011 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 More sharing options...
Void Singer Posted August 28, 2011 Share Posted August 28, 2011 it might help more to know what the dialogs are supposed to spit out at each level, but I can see that in that script immediately, you only check if you have a first level command.... and do nothing if it's a second or third level... Link to comment Share on other sites More sharing options...
Tabris Daxter Posted August 28, 2011 Author Share Posted August 28, 2011 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 More sharing options...
Void Singer Posted August 28, 2011 Share Posted August 28, 2011 if (menulvl1 != -1) test that the command is one of the lvl1 commands, but your lvl2 command check is nested inside of that test, so it will NEVER be true... you need to move that test outside of the first test. Link to comment Share on other sites More sharing options...
Tabris Daxter Posted August 29, 2011 Author Share Posted August 29, 2011 /facepalm Link to comment Share on other sites More sharing options...
Recommended Posts
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