Any way to get an agent name from their key?
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-30-2004 13:10
Searching for anything with "key" in it is impossible in this forum cause of the 4-letter minimum. Oh well.
My trivia script is coming along nicely. It spits out questions, listens for input from multiple people and then says when it hears the correct answer.
Now to my next dataserver delimna.
I am able to successfully get the key of the user who says the correct answer, and when I try to use llRequestAgentData, I'm asking for the DATA_NAME info, but it's returning a (seemingly) random key to me every time.
I know why my agent's key is. When I remove the llRequestAgentData call, and have it say, "Congratulations, KEY, you got it right!", where KEY is is my correct key, or whoever said the correct answer. The problem seems to once again be with he dataserver event...
Can I have multiple dataserver events in a script? If so, how do I keep the one that's calling for DATA_NAME separate from the one that's pulling data from my notecards?
I actullay need three different dataservers. One to read my settings notecard, one to grab my questions, and one to get the name of the person who answers correctly.
P.S. I hate dataserver.
|
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
|
07-30-2004 13:29
Erm, I know this is a lot like asking "is it plugged in?" but why can't you use the "name" parameter passed in to your listen event, it gives the name of whatever's speaking.
_____________________
Sarcasm meter: 0 |-----------------------*-| 10 Rating: Awww Jeeze!
|
Zak Escher
Builder and Scripter
Join date: 3 Aug 2003
Posts: 181
|
07-30-2004 13:31
I think this may do what you want
A.118. llKey2Name
string llKey2Name(key id);
If object id is in the same simulator, return the name of the object.
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-30-2004 19:34
From: someone Originally posted by Zak Escher I think this may do what you want
A.118. llKey2Name
string llKey2Name(key id);
If object id is in the same simulator, return the name of the object. Bingo! That did it in one simple call.  Thanks Zak!
|
Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
|
Re: Any way to get an agent name from their key?
07-31-2004 06:44
From: someone Originally posted by Aaron Levy Can I have multiple dataserver events in a script? If so, how do I keep the one that's calling for DATA_NAME separate from the one that's pulling data from my notecards?
I actullay need three different dataservers. One to read my settings notecard, one to grab my questions, and one to get the name of the person who answers correctly.
P.S. I hate dataserver. Sure, but only in a way. There is only one dataserver event per state. But you want to make 3 different requests, and be able to tell which one is coming back in the dataserver event. To do this, you have to use an IF conditional statement to differentiate between the different UUID values given back to you from the llReqestAgentData function. Here is an example (you can also find this and many more examples at the University of Second Life's Library in Phobos)... llRequestAgentData DataServer Example //llRequestAgentData DataServer Example //by Hank Ramos key nameRequestID; key bornRequestID; key ratingRequestID;
default { state_entry() { llSay(0, "Ready. Click to start."); } touch_start(integer num_detected) { integer x; //Loop through the number of Agents touching this prim for (x=0;x < num_detected; x += 1) { //Request the name of the Agent //Note: llKey2Name could be used, but it only works if the avatar //is currently located in the simulator nameRequestID = llRequestAgentData(llDetectedKey(x), DATA_NAME); //Request the born date of the Agent bornRequestID = llRequestAgentData(llDetectedKey(x), DATA_BORN); //Request the ratings of the Agent ratingRequestID = llRequestAgentData(llDetectedKey(x), DATA_RATING); } } dataserver(key queryid, string data) { list tempList; //Check to make sure this is the request we are making. //Remember that when data comes back from the dataserver, //it goes to *all* scripts in your prim. //So you have to make sure this is the data you want, and //not data coming from some other script.
//Check to see if the query is for the Agent Name if (queryid == nameRequestID) { llSay(0, "Your Name is: " + data); } //Check to see if the query is for the Agent Born Date if (queryid == bornRequestID) { llSay(0, "Your Were Born: " + data); } //Check to see if the query is for the Agent Ratings if (queryid == ratingRequestID) { tempList = llCSV2List(data); llSay(0, "Your Behavior Rating: +" + llList2String(tempList, 0) + " -" + llList2String(tempList, 1)); llSay(0, "Your Appearance Rating: +" + llList2String(tempList, 2) + " -" + llList2String(tempList, 3)); llSay(0, "Your Building Rating: +" + llList2String(tempList, 4) + " -" + llList2String(tempList, 5)); } } }
|
Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
|
07-31-2004 06:45
Here is a notecard reading example... (This and many more examples are available at the University of Second Life's Library in Phobos)... Read Notecard DataServer Example //Read Notecard DataServer Example //by Hank Ramos string notecardName = "My Notecard"; integer lineCounter; key dataRequestID;
default { state_entry() { llSay(0, "Ready. Click to start."); } touch_start(integer num_detected) { state readNotecard; } }
state readNotecard { state_entry() { lineCounter = 0; dataRequestID = llGetNotecardLine(notecardName, lineCounter); } dataserver(key queryid, string data) { //Check to make sure this is the request we are making. //Remember that when data comes back from the dataserver, //it goes to *all* scripts in your prim. //So you have to make sure this is the data you want, and //not data coming from some other script. if (queryid == dataRequestID) { //If we haven't reached the end of the file //Display the incoming data, then request the next line # if (data != EOF) { dataRequestID = llGetNotecardLine(notecardName, lineCounter); lineCounter += 1; llSay(0, "Line #" + (string)lineCounter + ": " + data); } else { state default; } } } }
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
07-31-2004 21:42
touch events should pass llDetectedName(x)
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
|
08-02-2004 06:15
Yes  My examples tend to use silly situations to teach a concept. You can of course use llDetectedName(x), and get the name of the person who triggers the touch_start without having to resort to using the slow dataserver event. I used the touch_start event so that somebody could copy-paste the script into a cube, and immediately see it function so they can see how it works. However, you'll need to use the DataServer event when you have the key of an agent, but haven't stored their name (memory limitations) and they aren't in the simulator at the time (required for llKey2Name to work). This is typical in scripts where you may keep a list of agent keys, and don't keep a list of thier names because you are short on memory.
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
08-02-2004 15:44
just giving my 4L$ worth 
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|