CampSoup1988 Posted June 16, 2011 Share Posted June 16, 2011 Ok, lets say I want to track the donations of three people. I have a variable called DonationTotal which stores [0,0,0]I have tried a number of ways to update lets say the second number in the list, but I keep getting errors. Oh, and Current has the integer 2. These are the different methods I have tried and their errors:llList2Integer(DonationTotal, Current) += amount; but I got: The left-hand side of an assignment must be a variable, property or indexer DonationTotal[current] += amount; and got:Expected ; or = (cannot specify constructor arguments in declaration); expectedInvalid expression term '+='; expected I also tried a few other similar combinations, which got me the same results of those previous two attempts. If anyone has any advice, I would be greatly appreciated! Thank you,CampSoup1988 Link to comment Share on other sites More sharing options...
Cerise Sorbet Posted June 16, 2011 Share Posted June 16, 2011 Hi, LSL llists look like they should behave as arrays from other languages, but they do not. We need to use helper functions. We can't do DonationTotal[current] += amount; but instead you might use -- DonationTotal = llListReplaceList(DonationTotal, [llList2Integer(DonationTotal, current) + amount], current, current); The LSL List category page has more information and other options to juggle them. Link to comment Share on other sites More sharing options...
CampSoup1988 Posted June 16, 2011 Author Share Posted June 16, 2011 So I have to replace the entire list.... I was kind of hoping to avoid that as in reality the list would be a lot longer then just three varaible. Actually it is open ended depending on how many staffers are added to the list And yes, I had previously dug deeply into that wiki. Link to comment Share on other sites More sharing options...
Cerise Sorbet Posted June 16, 2011 Share Posted June 16, 2011 CampSoup1988 wrote: So I have to replace the entire list.... Yes. Sometimes we can lessen the memory pain if we chop the lists, do lots of work, then reassemble them at the end, but there is not too much flexibility. Link to comment Share on other sites More sharing options...
CampSoup1988 Posted June 16, 2011 Author Share Posted June 16, 2011 As far as I know, I dont think my idea would even be possible then, since I dont have a fixed size for the list and to be honest, I would naturally have done DonationTotal[current]+=ammount; Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted June 16, 2011 Share Posted June 16, 2011 There are almost always ways to do stuff in lsl - mot of the fun you have when coding lsl is to find ways to make somthing work that dorn't work in the straight forward way. Link to comment Share on other sites More sharing options...
Helium Loon Posted June 16, 2011 Share Posted June 16, 2011 Knowing the list length isn't an issue, since it is available using llGetListLength(list). The typical way of doing this is already laid out in the wiki as an example function from the LSL_List page, though you'd have to alter it to use an index instead of 'searching' the list for a match (which isn't hard.) ListItemReplace function If you want to have it do something other than strings, you can change the function parameters to utilize another type, or even generalize the function by extending it to take in an integer that is the return from a llGetListEntryType() call, and use that to convert the input 'newvalue' to the correct type. Link to comment Share on other sites More sharing options...
CampSoup1988 Posted June 16, 2011 Author Share Posted June 16, 2011 I dont see how you could modify ListItemReplace to search by index instead of the content of the list Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 17, 2011 Share Posted June 17, 2011 As written, the function uses llListFindList to create the variable placeinlist, but if you already know where the item you want to replace is, you don't have to look for it. Just pass the function your known value of placeinlist and then use llListReplaceList to do the update. Link to comment Share on other sites More sharing options...
CampSoup1988 Posted June 20, 2011 Author Share Posted June 20, 2011 Ahhh, I totally overlooked that! Thank you Link to comment Share on other sites More sharing options...
Void Singer Posted June 20, 2011 Share Posted June 20, 2011 you can also limit lists to a specific length by adding and then only grabbing elements from the front or the back (depending on where you are adding and which ones are important. Link to comment Share on other sites More sharing options...
Miranda Umino Posted June 21, 2011 Share Posted June 21, 2011 This code below costs many creation of lists .. Let s cross fingers that the garbage collector works well list ListReplaceIntegerElementByIndex(list l , integer index , integer value){ return llList2List( l , 0, index -1 ) + (list)value + llList2List( l , index +1 , -1 );}default{ state_entry() { // displays Object: 10, 20, 30, 40, 1000, 60, 70, 80, 90 llOwnerSay(llList2CSV( ListReplaceElementByIndex( [ 10, 20, 30, 40, 50, 60, 70, 80, 90 ], 4, 1000))); }} Link to comment Share on other sites More sharing options...
Void Singer Posted June 21, 2011 Share Posted June 21, 2011 what wrong with l = llListReplaceList( l, [value], index, index ); ?? Link to comment Share on other sites More sharing options...
Miranda Umino Posted June 22, 2011 Share Posted June 22, 2011 :matte-motes-big-grin-squint: void , my bad .. i was tired ... Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now