Pedlar Decosta Posted February 12, 2023 Share Posted February 12, 2023 (edited) I am being confounded by an issue with a result from llListFindList. I've stripped the script down to essentials and added feedback all over to try and find the issue. Can anyone tell me what could possibly be causing this. I am using a user notecard for an extended user access. This is in the state entry if (llGetInventoryType(NOTECARD) == INVENTORY_NOTECARD) { NOTECARDLINE = 0; QueryID = llGetNotecardLine( NOTECARD, NOTECARDLINE ); } else { llSay(0,"No Specific 'users' notecard, access will only be set via menu"); } The touch event is; touch_start(integer num) { ONLIST = FALSE; CURRENTUSERKEY = llDetectedKey(0); CURRENTUSERNAME = llDetectedName(0); llOwnerSay("user list is "+llList2CSV(USERS)); llOwnerSay("current user "+llToLower(llKey2Name(CURRENTUSERKEY))); integer index = (~llListFindList( USERS, [llDetectedName(0)])); if(index != -1){ONLIST = TRUE;llOwnerSay("user onlist = TRUE");} llOwnerSay("ONLIST = "+(string)ONLIST); } This is the feedback I'm getting; [17:11] Object: user list is jeremiah bullfrog, ben linden [17:11] Object: current user andie resident [17:11] Object: user onlist = TRUE [17:11] Object: ONLIST = 1 [17:11] Object: onlist: 0 The llListFindList() seems to be returning '!= -1' when the name is not on the list ? I was intially using CURRENTUSERKEY and also tried CURRENTUSERNAME both converted into lowered trimmed strings. They exist for the dialogue menu, but I still have the same issue of the ' != -1' result when they aren't on the list. This is the dataserver; dataserver(key queryid, string data) { string name; list temp; string value; if (queryid == QueryID) { if(data != EOF) { if(llGetSubString(data, 0, 0) != "#" && llStringTrim(data, STRING_TRIM) != "") { temp = llParseString2List(data, [], []); name = llStringTrim(llToLower(llList2String(temp, 0)), STRING_TRIM); list temp2 = llParseString2List(name, [], []); value = llStringTrim(llList2String(temp2, 0), STRING_TRIM); USERS = llParseString2List(value, [","], []); } NOTECARDLINE++; QueryID = llGetNotecardLine( NOTECARD, NOTECARDLINE ); } else { return; } } } Edited February 12, 2023 by Pedlar Decosta Link to comment Share on other sites More sharing options...
Love Zhaoying Posted February 12, 2023 Share Posted February 12, 2023 6 minutes ago, Pedlar Decosta said: The llListFindList() seems to be returning -1 when the name is not on the list ? That is how llListFindList() works. If it finds the entry, it returns the 0-based index where it was found. If it does not find the entry, it returns "-1". Link to comment Share on other sites More sharing options...
Frionil Fang Posted February 12, 2023 Share Posted February 12, 2023 You seem to be specifically doing a binary negation (~) of the result here: integer index = (~llListFindList( USERS, [llDetectedName(0)])); This means index will be 0, if llListFindList returns -1. Remove the negation operator and you probably get what you wanted. 1 1 Link to comment Share on other sites More sharing options...
Love Zhaoying Posted February 12, 2023 Share Posted February 12, 2023 37 minutes ago, Frionil Fang said: You seem to be specifically doing a binary negation (~) of the result here: integer index = (~llListFindList( USERS, [llDetectedName(0)])); This means index will be 0, if llListFindList returns -1. Remove the negation operator and you probably get what you wanted. Good catch! When I see someone doing the (~) trick, I assume it's on purpose! (Something I'd never do so I ignore the code..figure they knew..) Link to comment Share on other sites More sharing options...
Pedlar Decosta Posted February 12, 2023 Author Share Posted February 12, 2023 I was using the ~ because of the wiki example.. So I removed the ~ and onlist still comes back as false ? Wiki; if(~llListFindList(myList, (list)item)) {//it exists // This works because ~(-1) produces 0, but ~ of any other value produces non-zero and causes the 'if' to succeed // So any return value (including 0) that corresponds to a found item, will make the condition succeed // It saves bytecode and is faster then doing != -1 // This is a bitwise NOT (~) not a negation (-) } Link to comment Share on other sites More sharing options...
Frionil Fang Posted February 12, 2023 Share Posted February 12, 2023 Not sure I follow anymore, but FALSE is equal to 0. 0 is a valid index - the thing was found at index 0 in the list. -1 is what you get when the thing is not found. Like the wiki example explains, the negation trick is for saving memory/performance but it does make it harder to read, so you could just stick to "index = llListFindList(needle, haystack)" and "if(index >= 0)" to maintain ease of following the code. Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted February 12, 2023 Share Posted February 12, 2023 Sometimes I wonder whether these tricky shortcuts/optimizations belong to wiki examples or if they should be replaced by simpler examples. A single symbol requires 4-5 lines of explanation, and even more to explain why it won't work in this context. 2 Link to comment Share on other sites More sharing options...
Pedlar Decosta Posted February 12, 2023 Author Share Posted February 12, 2023 I tried it with and without the ~ and then I tried it differnetly like this; if(~llListFindList( USERS, [llDetectedName(0)])){ONLIST = TRUE;llOwnerSay("user onlist = TRUE");} With the ~ it reports False whether the name is on the list or not and conversely positive for both if I remove the ~. Link to comment Share on other sites More sharing options...
KT Kingsley Posted February 12, 2023 Share Posted February 12, 2023 Just a quick glance at the code here (so I'm likely way off line) but this bit isn't usual: integer index = (~llListFindList( USERS, [llDetectedName(0)])); if(index != -1){ONLIST = TRUE;llOwnerSay("user onlist = TRUE");} If the variable index is assigned the return from ~llListFindList it will never equal -1 because ~(-1) is 0. Try integer index = (llListFindList( USERS, [llDetectedName(0)])); if(~index){ONLIST = TRUE;llOwnerSay("user onlist = TRUE");} In the quoted wiki example the value of ~llListFindList is not saved. It is usual here to save the returned index from llListFindList, and then test (~index) and if that's non-zero to use the value of index in any further operations. Hope this doesn't further muddy the waters if I've got it completely wrong. Link to comment Share on other sites More sharing options...
Pedlar Decosta Posted February 12, 2023 Author Share Posted February 12, 2023 13 minutes ago, Wulfie Reanimator said: Sometimes I wonder whether these tricky shortcuts/optimizations belong to wiki examples or if they should be replaced by simpler examples. A single symbol requires 4-5 lines of explanation, and even more to explain why it won't work in this context. So I should try something like index = (llListFindList(BlahBlah){if (index != -1){ show result} ? 1 Link to comment Share on other sites More sharing options...
Pedlar Decosta Posted February 12, 2023 Author Share Posted February 12, 2023 5 minutes ago, KT Kingsley said: Just a quick glance at the code here (so I'm likely way off line) but this bit isn't usual: integer index = (~llListFindList( USERS, [llDetectedName(0)])); if(index != -1){ONLIST = TRUE;llOwnerSay("user onlist = TRUE");} If the variable index is assigned the return from ~llListFindList it will never equal -1 because ~(-1) is 0. Try integer index = (llListFindList( USERS, [llDetectedName(0)])); if(~index){ONLIST = TRUE;llOwnerSay("user onlist = TRUE");} In the quoted wiki example the value of ~llListFindList is not saved. It is usual here to save the returned index from llListFindList, and then test (~index) and if that's non-zero to use the value of index in any further operations. Hope this doesn't further muddy the waters if I've got it completely wrong. I tried it and got a negative both times with the name on the list and not on the list. I'm obviously not understanding this. Link to comment Share on other sites More sharing options...
Pedlar Decosta Posted February 12, 2023 Author Share Posted February 12, 2023 Ok, I haven't fixed the actual issue but I think I know the problem. When I add the name to the users notecard and don't leave a space after the comma of the previous name, the code works as expected. So I'm assuming there is an issue with the trimming of the elements of the USER list. I thought the code above trimmed the user list of spaces, but it certainly appears like there is a space before the user name/s. Can anyone tell me what they error is ? Once I manually remove the space most of the methods suggested work. But for user convenience I don't want to have to make them leave spaces out of the list ? Link to comment Share on other sites More sharing options...
Frionil Fang Posted February 12, 2023 Share Posted February 12, 2023 Use llStringTrim(name, STRING_TRIM) to remove whitespace from both sides before adding it to the list. Link to comment Share on other sites More sharing options...
Pedlar Decosta Posted February 12, 2023 Author Share Posted February 12, 2023 13 minutes ago, Frionil Fang said: Use llStringTrim(name, STRING_TRIM) to remove whitespace from both sides before adding it to the list. Thanks Frionil, however I have that in 3 places when compiling the list already. And unsure why it hasn't worked. i.e.- if(llGetSubString(data, 0, 0) != "#" && llStringTrim(data, STRING_TRIM) != "") { temp = llParseString2List(data, [], []); name = llStringTrim(llToLower(llList2String(temp, 0)), STRING_TRIM); list temp2 = llParseString2List(name, [], []); value = llStringTrim(llList2String(temp2, 0), STRING_TRIM); USERS = llParseString2List(value, [","], []); Link to comment Share on other sites More sharing options...
Pedlar Decosta Posted February 12, 2023 Author Share Posted February 12, 2023 (edited) Does anyone understand why the space in the user list names don't get trimmed ? I can put it in the instructions that they don't leave spaces between the commas and the names, but realistically, to be user friendly, it would be best if the spaces just got trimmed automatically. I've posted the relevant code earlier or above. But unless I remove the spaces in the user notecard, it gives incorrect results when I search for the name. Any advise or opinions are appreciated. Edited February 12, 2023 by Pedlar Decosta Link to comment Share on other sites More sharing options...
Qie Niangao Posted February 12, 2023 Share Posted February 12, 2023 1 hour ago, Pedlar Decosta said: Does anyone understand why the space in the user list names don't get trimmed ? That's because llStringTrim only removes the space from the very beginning of the string, the very end of the string, or both, not from inside the string. What makes this messy is you can't simply remove all spaces from inside the whole string (which would be easy enough with llParseString2List(data, [",", " "], []); ) because some of the names include spaces that you want to preserve, so you'll need to string trim each element of the list individually. An alternative llCSV2List() works for strings that don't contain spaces preceding other spaces or commas, nor stray ">"s or "<"s. It makes the code simple, but not as obsessively user friendly about what they may put in the notecard as wading through the whole USER list, string-trimming each element. 1 Link to comment Share on other sites More sharing options...
Pedlar Decosta Posted February 12, 2023 Author Share Posted February 12, 2023 48 minutes ago, Qie Niangao said: ....so you'll need to string trim each element of the list individually. Right. Ok. Thanks. I can do that. Some of these functions confuse me a little bit. I thought that was being done in the compiling code above before it added it to the list. But I can write code to do each individually and add them individually to the user list. Thanks mate. 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