Tommy Oz
Registered User
Join date: 13 Jan 2005
Posts: 56
|
01-30-2005 17:18
What is the most straight forward way to get a string value input from the user?
I need to get several srting values from the user in a script. How do I use listen() is a way that doesn't brake the logic control? I would thing data entry would be a basic function. I must be missing something very obvious.
|
Tommy Oz
Registered User
Join date: 13 Jan 2005
Posts: 56
|
01-30-2005 17:19
Sorry. These need to be values to specific promts.
|
Tread Whiplash
Crazy Crafter
Join date: 25 Dec 2004
Posts: 291
|
User inputs...
01-30-2005 20:50
Tommy - The most straightforward way is with a listen on a specific channel, then filter the user's commands with an "if" statement... If you have different inputs the user should give, one easy way is to have them type the input's name, then the value - with a seperation character between them. For example, the user could type "/5000 set_color|red" (speaking on channel 5000, and trying to set the object's color to red). This could be checked by the script with the following code (which takes the color and prints it out in a chat message): //Pick some sort of channel to listen on. integer g_uiListenChannel = 5000;
//Set up the Listener itself integer listenHandle = llListen(g_uiListenChannel,"","",""); . . . . . //"message" may contain multiple commands or parameters, // each seperated by the "|" character. // This is called a "pipe" character (SHIFT + backslash Key).
listen(integer channel, string name, key id, string message) { list parsedMessage; parsedMessage = llParseString2List(message,["|"],[]); //Do Some processing in here with the parsed message. //For example: if(llList2String(parsedMessage,0) == "say_hi") llSay(0, "Hi!");
else if(llList2String(parsedMessage,0) == "set_color") { if(llList2String(parsedMessage,1) == "red") g_someColorVector = <1.0,0,0>; else if(llList2String(parsedMessage,1) == "blue") g_someColorVector = <0,0,1.0>; else if(llList2String(parsedMessage,1) == "green") g_someColorVector = <0,1.0,0>;
llSay(0, "My color is now: "+llList2String(parsedMessage,1)); } }
Hope this helps! Take care, --Noel "HB" Wade (Tread Whiplash) P.S. For more information on the listen() event or the "ll" built-in functions, see the LSL Wiki: http://secondlife.com/badgeo/wakka.php?wakka=HomePage
|
Tread Whiplash
Crazy Crafter
Join date: 25 Dec 2004
Posts: 291
|
Alternatively...
01-30-2005 21:00
OR, if you want to be a bit more complicated & prone to sequencing bugs - you COULD track your progress, and treat each user's message as a response to the last prompt. Like this: //Assume that we have some global variables to track user-settable information. //They all start with "g_user..."
//Elsewhere, this code prompts the user for a color, then a name, then a favorite food.
//Pick some sort of channel to listen on. integer g_uiListenChannel = 5000;
integer g_currentPrompt = 1;
//Set up the Listener itself integer listenHandle = llListen(g_uiListenChannel,"","",""); . . . . .
listen(integer channel, string name, key id, string message) { if(g_currentPrompt == 1) g_userColorString = message; else if(g_currentPrompt == 2) g_userName = message; else if(g_currentPrompt == 3) g_userFavoriteFood = message; g_currentPrompt++; }
The down-side to this sort of method, is that you can't guarantee the user is responding to the right message - you just know they're telling you something, and you know the last thing you sent out... There are lots of possible bugs and ways that this could go wrong. Explicitly setting the parameters, like I demonstrated in my first reply, is a better way of doing things IMHO. I'm only posting this to show off different methods and hopefully to get your brain thinking along different lines. Take care, --Noel "HB" Wade (Tread Whiplash)
|