Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-28-2004 23:28
I've been trying to do this for the past four hours and really need some help.
I'm pulling trivia questions from a notecard. Each line of the notecard has a question, then a "*" and the answer. I can get my script to pick a question by random, but I can't figure out for the life of me how to separate the two.
When it loads a notecard line, I'd like it to split everything before the * into strQuestion and then everything after the * into strAnswer. That way I can work with each separatly.
I've used llSubString in the past, but I don't think that it has the functionality to recognize the delimeter. Ugh.
Any help would be greatly appreciated. Thanks!
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-28-2004 23:49
Ok, I think it has to do with llParseString2List...
How do I name the list that this creates, you know how you name a list to work with it?
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
07-28-2004 23:52
There are two ways you can do this: A: Using llParseString2List B: Using llGetSubString, llDeleteSubString and llSubStringIndex.
I prefer A, since I dont feel like dealing with the all-too-common off-by-one errors I have to debug every time I use the string manipulators.
The way you can do this is by passing the notecard line text to llParseString2List like this:
llParseString2List(lineText, ["*"], []);
This line will split your text into seperate list elements wherever * occurs. * will never appear in any of the list elements.
For example, if you pass the string "Question*Answer" to llParseString2List, and fill in the parameters above, youll get the list ["Question", "Answer"]
You can then pull out the first element, index 0, using llList2String(parseResult, 0), which would return "Question". The same can be repeated for index 1.
Using the llGet/DeleteSubString and llSubStringIndex functions, you can go about it like this:
// Your question/answer seperator. string delim = "*"; // Get the position (index) of the delimeter in the line. integer delimPos = llSubStringIndex(line, delim); // Get all the characters in line up to the index of the character occuring *before* delim occurs. string question = llGetSubString(line, 0, delimPos - 1);
// Get the string resulting from removeing all characters from line, including the character at delimPos (the delimeter). string answer = llDeleteSubString(line, 0, delimPos);
==Chris
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-28-2004 23:55
Thanks Christopher!! I feel smart!! I actually figured method A out just now, and came back here to post that I did!! Thanks for your reply though!! I'm just so happy I did it right!
(now i just need to understand states so i can make this thing work!!)
|