Lulu Ludovico
Registered User
Join date: 24 Jan 2005
Posts: 27
|
02-24-2005 06:54
I'm trying to translate a voice command into a list. Say the voice command syntax is "Pos 1,1,1" What is the script that can effectively transalte this into a list in the form [1,1,1]? I've been fooling around with: list myList = (list) llGetSubString(voiceCommand,4,length - 1); float myX = (float) llList2String(myList,0); float myY = (float) llList2String(myList,1); float myZ = (float) llList2String(myList,2);
But this doesn't quite work as only myX has the correct value, the rest are zero. Any ideas what's wrong and how to fix it?
|
Cadroe Murphy
Assistant to Mr. Shatner
Join date: 31 Jul 2003
Posts: 689
|
02-24-2005 07:08
I'm not sure I understand everything you're doing in your code, but here's an example of what I usually do. I don't know if it's the best way, but it works for me, so I just keep using it. listen(integer chan, string name, key id, string text) {
list cmdLine = llParseString2List(text, [" "], []); string cmd = llList2String(cmdLine, 0); cmd = llToLower(cmd); if (cmd == "pos") { vector pos; pos.x = llList2Float(cmdLine, 1); pos.y = llList2Float(cmdLine, 2); pos.z = llList2Float(cmdLine, 3); //do something with pos } }
_____________________
ShapeGen 1.12 and Cadroe Lathe 1.32 now available through SLExchange.
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
02-24-2005 07:50
I can't get in world at the moment but in outline what you want to do is chop off the front of the voice command ('pos ') and then you can use llCSV2List() on the rest. You will need to get the right way of addressing the components of the vector too Roughly speaking: string command=llGetSubString(voiceCommand, 4, -1); list myList=llCSV2List(command); vector myVector; myVector.x = (float)llList2String(myList,0); myVector.y = (float)llList2String(myList,1); myVector.z = (float)llList2String(myList,2);
Should work... apologies if it doesn't compile.
|
Lulu Ludovico
Registered User
Join date: 24 Jan 2005
Posts: 27
|
02-26-2005 04:53
From: Cadroe Murphy here's an example of what I usually do. I don't know if it's the best way, but it works for me, so I just keep using it. Thanks so much. I've tried it, and it works great. Didn't try the second one though, since the first one works, but thanks for responding too! 
|
Jack Lambert
Registered User
Join date: 4 Jun 2004
Posts: 265
|
02-26-2005 11:51
I normally do it exactly as Cadroe suggested, with llParseString2List ... the key is to make sure you have the proper "separators". You could have used [" ", ","] instead to find the commas, as well.
e.g.
llParseString2List(text, [" ", ","], []);
--Jack Lambert
|