When does LIST_STAT_MAX != max?
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-24-2010 16:50
This is my week for writing stats routines that don't work. Here's a simplified version of what I'm working on, with some strategic llOwnerSay statements. The longer version, with all the bells and whistles, behaves exactly the same way this stripped down one does. integer thisweek; integer lastweek; integer count = 35; list WeekStats = [];
weekreport() { list stats = llParseString2List(llGetObjectDesc(),[" "],[]); integer i; for (i=0;i< llGetListLength(stats);++i) { llOwnerSay("4. stats("+(string)i+") = " +llList2String(stats,i)); } llInstantMessage(llGetOwner(), "6. Final output = " + chart(stats)); }
string chart(list values) { integer min = llFloor(llListStatistics(LIST_STAT_MIN, values)); integer max = llCeil(llListStatistics(LIST_STAT_MAX, values)); llOwnerSay("5. Maximum value in stats = " +(string)max); return (string)max; } default { state_entry() { thisweek = 10; llSetObjectDesc((string)thisweek); //Dummy for testing }
touch_start(integer total_number) { llOwnerSay("1. Initial Obj Desc = " +llGetObjectDesc()); lastweek = thisweek; thisweek = count - lastweek; WeekStats = llParseString2List(llGetObjectDesc(),[" "],[]) + thisweek; llOwnerSay("2. Updated Stats = " + llDumpList2String(WeekStats," ")); llSetObjectDesc(llDumpList2String(WeekStats," ")); llOwnerSay("3. New Obj Desc = "+ llGetObjectDesc()); weekreport(); } }
If I set this script in a prim and click it, here's the output ... [16:33] Object: 1. Initial Obj Desc = 10 [16:33] Object: 2. Updated Stats = 10 25 [16:33] Object: 3. New Obj Desc = 10 25 [16:33] Object: 4. stats(0) = 10 [16:33] Object: 4. stats(1) = 25 [16:33] Object: 5. Maximum value in stats = 0 WHAT!!!! Should be = 25![16:33] Object: 6. Final output = 0 What the heck is going on? I know what's in the list named "stats." I just read it out with my fourth llOwnerSay. It has two values in it: 10 and 25. The biggest one is 25, and I'm pretty sure that 25 != 0.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-24-2010 20:11
OK.... I keep poking at this thing and I know where the problem is. I just don't understand WHY it's a problem. I can get the script to work if I do this .... weekreport() { list stats = llParseString2List(llGetObjectDesc(),[" "],[]); integer i; for (i=0;i< llGetListLength(stats);++i) { llOwnerSay("4. stats("+(string)i+") = " +llList2String(stats,i)); } llInstantMessage(llGetOwner(), "6. Final output = " + chart(WeekStats)); }
or this ..... touch_start(integer total_number) { llOwnerSay("1. Initial Obj Desc = " +llGetObjectDesc()); lastweek = thisweek; thisweek = count - lastweek; WeekStats = llParseString2List(llGetObjectDesc(),[" "],[]) + thisweek; llOwnerSay("Here's a shortcut directly to chart >> " + chart(WeekStats)); llOwnerSay("2. Updated Stats = " + llDumpList2String(WeekStats," ")); llSetObjectDesc(llDumpList2String(WeekStats," ")); llOwnerSay("3. New Obj Desc = "+ llGetObjectDesc()); weekreport(); }
So there's something wrong with the way I'm storing and retrieving WeekStats in the object's description field. I just can't see it for the life of me.  It actually looks as if the updated information in the description field isn't persistent. Is this related to SVC-3429?
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
01-24-2010 20:48
At the risk of making myself look stupid (again), could it be that llParseString2List returns everything as type string, which is then ignored by llListStatistics?
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-24-2010 20:59
Nope. llParseString2List does just what it says..... takes a string and turns it into a list. It returns a list. I shouldn't get a compile error for a type mismatch, and I don't.
I can get the routine to work if I feed it the updated list WeekStats directly, as I indicated in my last post. It screws up when it has to write that list to the object's description field and then read it out again later, so it has something to do with that process. The maddening thing, if you look at the output in my OP, is that the field description looks like it has been updated properly. When I print out its contents with llOwnerSay, they look just fine.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
01-24-2010 21:17
http://wiki.secondlife.com/wiki/LlParseString2List#CaveatsFrom: someone All entries in the return are typed as string. Use explicit typecasting on llList2String to convert the values into other types. Do not rely upon the implicit typecasting of the other llList2* functions (as they typically return a default value); http://wiki.secondlife.com/wiki/LlListStatistics#SummaryFrom: someone If a list entry type is not a float or an integer it is silently ignored.
|
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
|
01-24-2010 21:27
Pete is right, statistics don't work on strings : list convert(list source) { list dest = [] ; integer i ; for (i=0;i< llGetListLength(source);++i) { dest += llList2Integer(source, i) ; } return dest ; }
default { state_entry() { }
touch_start(integer total_number) { list l = ["10", "25"] ; list m = convert(l) ; llOwnerSay("l max : " + (string)llListStatistics(LIST_STAT_MAX, l)) ; llOwnerSay("m max : " + (string)llListStatistics(LIST_STAT_MAX, m)) ; } }
Now that leads to interesting side effects such as with: list l = [10, 25, "5", "30"] ; Not sure what to do with it though.
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-25-2010 05:41
Thanks. I'll give it a shot this morning and see what happens.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
WooHoo!! Success!
01-25-2010 06:49
Pete, I love you (at least today). That was it. I did an explicit typecast of the list's elements to integer and the script works like a charm. Add one more quirky fact to my toolbox. Thanks. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
01-25-2010 07:00
From: Rolig Loon Pete, I love you (at least today). That was it. I did an explicit typecast of the list's elements to integer and the script works like a charm. Add one more quirky fact to my toolbox. Thanks.  Stickify please 
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-25-2010 12:05
must remember: list elements have their own types (and not all list2* perform casting, although they should IMO)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-25-2010 13:18
Gotcha, Void. That one defied logic. I didn't see it coming and, frankly, if I had run headfirst into that arcane caveat note that Pete quoted I still wouldn't have seen it coming. "All entries in the return are typed as string. Use explicit typecasting on llList2String to convert the values into other types."? It would be less opaque to say, "All elements in the list returned by llList2String are strings, and must be explicitly typecast if they are to be used as other types." Just a suggestion ..... 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-25-2010 14:03
From: Rolig Loon Gotcha, Void. That one defied logic. I didn't see it coming and, frankly, if I had run headfirst into that arcane caveat note that Pete quoted I still wouldn't have seen it coming. "All entries in the return are typed as string. Use explicit typecasting on llList2String to convert the values into other types."? It would be less opaque to say, "All elements in the list returned by llList2String are strings, and must be explicitly typecast if they are to be used as other types." Just a suggestion .....  good suggestion, you should log on and change that (that change would be pretty painless, it should be on the actual page instead of buried in some template)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|