Talk:Notecard Configuration Reader by Maddox Deluxe
Suggestions
Hello Maddox
You might find this code easier for validating a key:
<lsl> integer isKey(string test) {
if ( (key) test) return TRUE; return FALSE;
} </lsl>
That's all you need to do. There's no need for the detailed inspection you have coded in your isKey() function.
You start your notecard reading by requesting the number of notecard lines - but you never use this information, in fact it appears that you will attempt to process the returned number of lines as if it were line #0 of the notecard itself, and you'll never process the true contents of line 0. In your application, I see no reason to request the number of lines. Just start by requesting a read of line #0.
Your IsElement() function is intended, I think, to ensure that a found texture name occurred at an index that was a multiple of 3. But it doesn't do so at all. Once the code passes the <lsl> if (~index) </lsl> test, it's bound to return TRUE.
Try this:-
<lsl> integer IsElement(list db, string search) {
integer index = llListFindList(db, [search]); if ( ! (index % 3 ) )
return TRUE; // was found on a stride boundary
return FALSE; // was not found
} </lsl>
Your code <lsl>
++line; notecardQueryId = llGetNotecardLine(GetNoteName, line);
</lsl> would be better placed up where you have put the comment: // speed is the key when scripting, ... At present your code will stall on the first error encountered, as it will not go on to read the next notecard line, and will never reach EOF.
Why ask the user to code a full null key where no texture is desired? Why not look for a simpler specific string such as NONE?
I could go on, but that's enough ... except to say: do indent your code properly. You may find the offline tool lslEditor useful for this, as it has an auto-indent feature.
Omei Qunhua 02:05, 22 April 2014 (PDT)
Well Omei, there is many ways to code things and everyone has their own style, but this script works just how it was made to. It has been tested many ways for error checking with the notecard format. I made it from on going project of my, the demo script just shows how you could handle themes UUID keys and using list for them. The "Error Checking" is 100% good.
All you got to do is run the test scripts and you will see they work fine. The format notecard was not made to handle spaces, the comment lines works just fine as long you keep each line right under each other.
This will work.
// Comment 1 [Author Name] = Maddox Deluxe // Comment 2 [Menu Button Name] = Fantasy Tiger // Comment 3 [BackDrop Texture UUID] = 8f304cf2-7120-24e2-d1f1-db6b31bd6f6c // Comment 4 [FloorDrop Texture UUID] = 00000000-0000-0000-0000-000000000000 // Comment 5 [Menu Button Name] = Fantasy Car // Comment 6 [BackDrop Texture UUID] = 517b2288-67ca-b14c-1de2-c5f5fdf5291f // Comment 7 [FloorDrop Texture UUID] = 00000000-0000-0000-0000-000000000000 // Comment 8 [Menu Button Name] = Fantasy Tree // Comment 9 [BackDrop Texture UUID] = f6321118-cc24-6230-78a5-a257a3e33378 // Comment 10 [FloorDrop Texture UUID] = 00000000-0000-0000-0000-000000000000
or this will work to.
[Author Name] = Maddox Deluxe [Menu Button Name] = Fantasy Tiger [BackDrop Texture UUID] = 8f304cf2-7120-24e2-d1f1-db6b31bd6f6c [FloorDrop Texture UUID] = 00000000-0000-0000-0000-000000000000 [Menu Button Name] = Fantasy Car [BackDrop Texture UUID] = 517b2288-67ca-b14c-1de2-c5f5fdf5291f [FloorDrop Texture UUID] = 00000000-0000-0000-0000-000000000000 [Menu Button Name] = Fantasy Tree [BackDrop Texture UUID] = f6321118-cc24-6230-78a5-a257a3e33378 [FloorDrop Texture UUID] = 00000000-0000-0000-0000-000000000000
this will return error no data found.
[Author Name] = Maddox Deluxe [Menu Button Name] = Fantasy Tiger [BackDrop Texture UUID] = 8f304cf2-7120-24e2-d1f1-db6b31bd6f6c [FloorDrop Texture UUID] = 00000000-0000-0000-0000-000000000000 [Menu Button Name] = Fantasy Car [BackDrop Texture UUID] = 517b2288-67ca-b14c-1de2-c5f5fdf5291f [FloorDrop Texture UUID] = 00000000-0000-0000-0000-000000000000 [Menu Button Name] = Fantasy Tree [BackDrop Texture UUID] = f6321118-cc24-6230-78a5-a257a3e33378 [FloorDrop Texture UUID] = 00000000-0000-0000-0000-000000000000
It does not handle spaces over the error checking, I had change the codes, but it did handle spaces at first. I will work the spaces part out and fix it later. I do know I should had not rush and try to share the script so fast, I'm bad at that and should had did more testing before hand. v1.3 not bad, just can't use spaces right now. I been out of second life for a long time, but I'm sure the scripting has change a lot over the months. The functions still does the job and seem to work very fast. Thanks for showing other ways to check things, from now on I will make sure the script is 100% done before sending it to the wiki.
- Thanks Maddox. You might like to try these bad keys, all of which will sail through your isKey() as valid, but all would be rejected by the much easier, shorter and FASTER if (MyKey) ... process.
<lsl> "8f3O4cf2-7120-24e2-d1f1-db6b31bd6f6c" "8f304cf2-7120-24e2-dlf1-db6b31bd6f6c" "8f304cf2-7120-24e2-d1f1-db6b31-bd6f6" </lsl>
The first has a letter O instead of 0 (4th character), the 2nd has a letter L instead of a 1 (2nd character in 4th group), and the last has an extra hyphen instead of a hex digit. Omei Qunhua 01:39, 26 April 2014 (PDT)
Thanks Qunhua, I will check things out soon. I need to get my butt to bed right now, thanks for update info.... Here I made a video for you to check out, showing the project with the script.
I remove the old video since the script is now working good. there is a new video on the main script page. [The Demo Script]
- Sorry to say there's still big problems. You might like to consider why your test returns a uuid starting with "8f30..." for Fantasy Car Backdrop Texture, when the correct UUID starts with "517b...". The reason is based on the fact that for every non-comment line in your notecard, you add 3 entries to your Themes list. So when you read the line [Fantasy Tiger] you add the string "Fantasy Tiger", AND two (default) null keys to Themes. Then when you read the line with [BACKDROP TEXTURE UUID] you add a further 3 entries, "Fantasy Tiger", the Backdrop UUID itself, and a Null key. Then when you read the [Floordrop Texture UUID] line, you add a FURTHER 3 entries: "Fantasy Tiger" again, the Backdrop UUID again, and the new Floordrop UUID. This process is repeated for every line of the notecard. So your lookup process is going to be a disaster. When you reach the "Fantasy Car" line, you add "Fantasy Car" to Themes, but you also add the old keys from Fantasy Tiger. Corrected entries follow on later in the database, but this is too late; your search will find the first (invalid) entry. Omei Qunhua 04:34, 26 April 2014 (PDT)
That is what second life copy asset UUID gave the images. Fantasy Tiger:8f304cf2-7120-24e2-d1f1-db6b31bd6f6c Fantasy Car:517b2288-67ca-b14c-1de2-c5f5fdf5291f Fantasy Tree:f6321118-cc24-6230-78a5-a257a3e33378 It all works and finds the tetxures and button names.
But in the test script it not 100% the same how the studio works, I will look into it and see. The strings for the search are return from the menu buttons linkmessage event, cause of the menu system that part does not work the same, but the codes should had work still. I am checking it now and will see what is up with it.
I see what is wrong, for some reason the test script is no longer setting the themes list format right. Damn, one thing after the other but in the studio the format is ok.
Crazy lol.. anyway I will work on it for a bit. I did some debug testing on both the studio and test script here.
Demo Script here
,,,Fantasy Tiger,,,Fantasy Tiger,8f304cf2-7120-24e2-d1f1-db6b31bd6f6c,,Fantasy Tiger,8f304cf2-7120-24e2-d1f1-db6b31bd6f6c, 00000000-0000-0000-0000-000000000000,Fantasy Car,8f304cf2-7120-24e2-d1f1-db6b31bd6f6c,00000000-0000-0000-0000-000000000000, Fantasy Car,517b2288-67ca-b14c-1de2-c5f5fdf5291f,00000000-0000-0000-0000-000000000000,Fantasy Tree, 517b2288-67ca-b14c-1de2-c5f5fdf5291f,00000000-0000-0000-0000-000000000000,Fantasy Tree, f6321118-cc24-6230-78a5-a257a3e33378,00000000-0000-0000-0000-000000000000
Studio script here
Fantasy Tiger,8f304cf2-7120-24e2-d1f1-db6b31bd6f6c,00000000-0000-0000-0000-000000000000, Fantasy Car,517b2288-67ca-b14c-1de2-c5f5fdf5291f,00000000-0000-0000-0000-000000000000, Fantasy Tree,f6321118-cc24-6230-78a5-a257a3e33378,00000000-0000-0000-0000-000000000000
Does not make since cause the studio adds the list the same way.
- BTW,, if you REALLY want to check that 4 consecutive characters are Hex, I'm pretty sure this would work:-
<lsl>
string char = llGetSubString(check, i, i+3 ); // (from your existing isKey() function) if ( (integer) ( "0x1" + char ) < 65536) return FALSE; ... etc.
</lsl> At least it'll be better than your existing test which fails miserably.
I explained why your Themes list is being built wrongly. It's due to where you've placed the Themes += statement. But it's not trivial to solve. A good exercise for you :) Omei Qunhua 14:59, 26 April 2014 (PDT)
Just crazy how the studio has the same line as the demo script, same place and same almost everything as far the notecard reading goes, but in the studio I move the list around and make new ones over the menu system. The studio works 100% with it all and as you see on the video I made.
In the studio at the end it has this <lsl>
llInstantMessage(id,"Themes Configuration Error on line: " +(string)LineIndex+ ". (1) The Floor-drop Texture UUID is empty. (2) The Floor-drop UUID is not a key."); llResetScript(); } ThemesCount = ThemesCount +1;
MainThemes += [Menu_Button_Name,Back_Drop_UUID,Floor_Drop_UUID]; // For the search list format Themes += [Menu_Button_Name+","+Back_Drop_UUID+","+Floor_Drop_UUID]; // For making the menu buttons format
} } }
</lsl> In the demo script <lsl>
llInstantMessage(id,"Themes Configuration Error on line: " +(string)LineIndex+ ". (1) The Floor-drop Texture UUID is empty. (2) The Floor-drop UUID is not a key."); llResetScript(); } ThemesCount = ThemesCount +1; // add +1 to our themes count }
// add to our test list database Themes += [Menu_Button_Name,Back_Drop_UUID,Floor_Drop_UUID];
} } }
</lsl>
Just the list format that stops it from working right, I will rewrite the demo script over and fix it all. The studio is 100% ok, I don't need to change anything as far the studio goes and It works just how it was made to, but I will test few things you said on the demo one.
I fix it, just had to move the list adding up like this.
<lsl>
llInstantMessage(id,"Themes Configuration Error on line: " +(string)LineIndex+ ". (1) The Floor-drop Texture UUID is empty. (2) The Floor-drop UUID is not a key."); llResetScript(); } ThemesCount = ThemesCount +1; // add +1 to our themes count Themes += [Menu_Button_Name,Back_Drop_UUID,Floor_Drop_UUID]; }
// add to our test list database //Themes += [Menu_Button_Name,Back_Drop_UUID,Floor_Drop_UUID];
} } }
</lsl>
Now the search will find the match on the test string search from any in the notecard. I will copy the version I got on here just to make sure and test it.
All works now, you can grab the update scripts and give it a test, change the search string to any of the buttons name in the notecard, it will pull out the right keys and names from it all. :) I did not even notice the studio and demo was not the same at the adding themes part. Gezzz my bad..
IsElement and DumpListFind is about the same code, but one just checks to make sure it was found first. All it does is pull the 3 elements from the list, cause each adding is done by 3 at a time.
List format = Fantasy Tiger,8f304cf2-7120-24e2-d1f1-db6b31bd6f6c,00000000-0000-0000-0000-000000000000 1. Fantasy Tiger (Search String) 2. 8f304cf2-7120-24e2-d1f1-db6b31bd6f6c (Backdrop Texture Key) 3. 00000000-0000-0000-0000-000000000000 (Floor Drop Texture Key)
This is why I had to make format for the dialog system to handle the buttons in other type of list.
This from Second Life Example of the [llListFindList]
<lsl> list numbers = [1, 2, 3, 4, 5]; default {
state_entry() { integer index = llListFindList(numbers, [3]); if (index != -1) { list three_four = llList2List(numbers, index, index + 1); llOwnerSay(llDumpList2String(three_four, ",")); // Object: 3,4 } }
} </lsl>
Easy Math :)
- Well if you don't want to try the 3 test keys I suggested, try this line in your notecard:
[FloorDrop Texture UUID] = a-STePID-and&-cras-fool-dumba-kee!!!
It sails through quite happily.
You took the easy route for 'fixing' the Themes list, but your reliance on sequence of the NC lines without checking the sequence, is fraught with danger. Asking the user to type in a full null key is expecting a lot. Your KeyNameCheck() should be simply an llListFindList(). Giving up on the first error is a cop-out. I would have a single Link Message, using the last param as the user key, and 'str' as the nc name, and 'num' as the message identifier. You're still requesting the number of nc lines, but not processing the resultant event. Your globals 'LineTotal' and 'data' are never used. Your IsElement() function still makes no sense - all you need is the first llListFindList() - the rest is redundant.
OK, I'll leave you too it now. Good luck! Omei Qunhua 11:07, 27 April 2014 (PDT)
Making a better key checker not bad idea, but I don't think ppl will be adding fake keys for their images in the studio, but still very nice script. For one they need to be good at scripting just to know how to fool the script with that fake key. If someone gave out a theme file and add that fake key it would cause llSetTexture to return a error message. IsElement() does make sense for the studio over the menu system, maybe not for this demo script, but it does in the menu system. Not going to get all into studio codes trying to show why it needs it. if(IsElement(Themes,"FAKE NAME")==TRUE) will just stop the dump list output. just a checker for true or false in the demo script. it is put to better use in the studio with the menu system. More like left it there for the demo script and show how it could be use for TRUE or FALSE for finding the button names.
Part of the studio linkmessage event dealing with dialogs. IsElement() is called isButton() in the studio, the DumpListFind() is called SetTheme() in the studio. The studio is using [Nargus Dialog Control script] to handle all the buttons and so on for the menu system.
<lsl> link_message(integer sender_num, integer num, string str, key id) {
if(num == lnkDialogTimeOut) { state default; }
else if(num == lnkDialogResponse)
{ if(IsButton(Themes,str)==TRUE) { SetTheme(Themes,str); Themes = TempThemes; ThemesPickMenu(User); llMessageLinked(LINK_THIS, lnkDialog, ThemesPickDialog, User); return; }
</lsl>
Only thing you could find bad was the key checking and how to fool it, everything else works great. But I will fix that part to. You can see how well the menu system does set the themes by using IsButton checker. [Video Here]
If you wanted to change the codes and display a error message about the search string part, you could change it to read like this for the demo script. <lsl>
if(IsElement(Themes,"Fantasy Tige")==FALSE) // we cause the search string to be FALSE; { llInstantMessage(id,"Themes Configuration Error. Button search string was not found."); llResetScript(); } else if(IsElement(Themes,"Fantasy Tiger")==TRUE) { DumpListFind(Themes,"Fantasy Tiger"); return; }
} </lsl>
So after the notecard gets read in and before it looks for the string name to dump the output, it will check it first with FALSE;