Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need some help with listen()

Kleston Axelbrad
Registered User
Join date: 27 Mar 2008
Posts: 23
08-18-2009 14:12
So the situation is, I need to ask a user a few questions, in which their answer will likely be completely different every time. I understand how llDialog works, but I can't figure out how to have a script listen for a single response, store it, and ask another question. I know it's possible, such objects exist (just look at FormTec if you don't know what I mean), I just can't figure it out. The questions will not change, so it will not run off of notecards. It's just how to properly listen for a single response that I can not find the information to do. Any help would be appreciated.

Thanks in advance!
Ceera Murakami
Texture Artist / Builder
Join date: 9 Sep 2005
Posts: 7,750
08-18-2009 14:33
Go over to the RUCE 1 sim, and in about the middle of the sim, by a big tree that is beside the walking path, you'll find a Knight (The Rutgers school mascott) that will, when spoken to, reply by addressing the last avatar who spoke by name. It also lists the name of the last person it heard in hovertext above his head.

I believe the scripts in it are full-perm and not blocked in any way from being viewed. Haven't looked with another avatar to see. But I made that, and I would be happy to share the script with you. Simple enough after detecting the fact that it was spoken to for your script to generate a random response in reply.
_____________________
Sorry, LL won't let me tell you where I sell my textures and where I offer my services as a sim builder. Ask me in-world.
Ceera Murakami
Texture Artist / Builder
Join date: 9 Sep 2005
Posts: 7,750
08-18-2009 14:44
Here's a simple chat-back script. I think I got it originally from the Script Library. For the script to work, everywhere that there is a < symbol, remove the blank space after that symbol. The Forum filters wouldn't let me post the script without adding those spaces.

// Script replies to anyone who talks within Chat range, and greets them by name.
// It also displays the name of the last person who it heard in hovertext above the prim.

key theDataNameKey;

integer sendableKeyings = 1;
integer receivedKeyings;

string theDataNameString;

// Set up the script

startup()
{
scrubKeys();
llOwnerSay("Setting up to chat";);
list lines = [llGetObjectName(), llGetObjectDesc()];
string label = llDumpList2String(lines, "\nI haven't heard anyone yet\n";);
llSetText(label, < 1.0, 1.0, 1.0>, 1.0);
}

// Forget old chat

scrubKeys()
{
llSetText("", < 0.0, 0.0, 0.0>, 1.0);

theDataNameKey = NULL_KEY;

receivedKeyings = 0;
}

// Float Name of the chatter above the object and reply

receiveKeys()
{
string text = theDataNameString + "\nis the last person\nthat I heard."
;
vector color = < 0.0, 1.0, 1.0>;
float opacity = 1.0;
llSetText(text, color, opacity);
llSay(0,"Hello " + theDataNameString + ". Welcome to our sim!\nHave a pleasant visit.";);
}

// Receive an image of the chatter

catchKey(key queryid, string data)
{
if (queryid == theDataNameKey)
{
theDataNameString = data;
}
}

// Ask to receive an image of the chatter in pieces

sendKeys(key who)
{
theDataNameKey = llRequestAgentData(who, DATA_NAME);
}

// For each reset ...

default
{

// Listen to all ordinary chat

state_entry()
{
startup();
llListen(0, "", NULL_KEY, "";);
}

// Ask to receive an image of the chatter in pieces

listen(integer channel, string name, key id, string message)
{
if (llGetAgentSize(id) != ZERO_VECTOR)
{
scrubKeys();
sendKeys(id);
}
}

// Receive every piece of an image of the chatter

dataserver(key queryid, string data)
{
catchKey(queryid, data);
receivedKeyings += 1;
if (receivedKeyings == sendableKeyings)
{
receiveKeys();
}
}

}
_____________________
Sorry, LL won't let me tell you where I sell my textures and where I offer my services as a sim builder. Ask me in-world.
Ceera Murakami
Texture Artist / Builder
Join date: 9 Sep 2005
Posts: 7,750
08-18-2009 14:59
In the above, right after the Listen that follows this line:

// Ask to receive an image of the chatter in pieces

You should be able to store the value of "message" into a variable for your script. That will be what the person said.
_____________________
Sorry, LL won't let me tell you where I sell my textures and where I offer my services as a sim builder. Ask me in-world.
Ceera Murakami
Texture Artist / Builder
Join date: 9 Sep 2005
Posts: 7,750
08-18-2009 15:08
Better version, that stores and uses the last reply it heard. Again, for the script to work, everywhere that there is a < symbol, remove the blank space after that symbol. The Forum filters wouldn't let me post the script without adding those spaces.


// Script replies to anyone who talks within Chat range, and greets them by name.

key theDataNameKey;

integer sendableKeyings = 1;
integer receivedKeyings;

string theDataNameString;
string LastChat;

// Say why chat with this script

startup()
{
scrubKeys();
llOwnerSay("Setting up to chat";);
list lines = [llGetObjectName(), llGetObjectDesc()];
string label = llDumpList2String(lines, "\nI haven't heard anyone yet\n";);
llSetText(label, < 1.0, 1.0, 1.0>, 1.0);
}

// Forget old chat

scrubKeys()
{
llSetText("", < 0.0, 0.0, 0.0>, 1.0);

theDataNameKey = NULL_KEY;

receivedKeyings = 0;
}

// Float an image of the chatter above the object

receiveKeys()
{
string text = theDataNameString + "\nis the last person\nthat I heard. And they said:\n" + LastChat;
vector color = < 0.0, 1.0, 1.0>;
float opacity = 1.0;
llSetText(text, color, opacity);
llSay(0,"Hello " + theDataNameString + ". Welcome to our sim!\nEnjoy your visit.";);
llSay(0,"I heard you say '" + LastChat + "'";);
}

// Receive an image of the chatter

catchKey(key queryid, string data)
{
if (queryid == theDataNameKey)
{
theDataNameString = data;
}
}

// Ask to receive an image of the chatter in pieces

sendKeys(key who)
{
theDataNameKey = llRequestAgentData(who, DATA_NAME);
}

// For each reset ...

default
{

// Listen to all ordinary chat

state_entry()
{
startup();
llListen(0, "", NULL_KEY, "";);
}

// Ask to receive an image of the chatter in pieces

listen(integer channel, string name, key id, string message)
{
LastChat = message;
if (llGetAgentSize(id) != ZERO_VECTOR)
{
scrubKeys();
sendKeys(id);
}
}

// Receive every piece of an image of the chatter

dataserver(key queryid, string data)
{
catchKey(queryid, data);
receivedKeyings += 1;
if (receivedKeyings == sendableKeyings)
{
receiveKeys();
}
}

}
_____________________
Sorry, LL won't let me tell you where I sell my textures and where I offer my services as a sim builder. Ask me in-world.
Kleston Axelbrad
Registered User
Join date: 27 Mar 2008
Posts: 23
08-19-2009 09:28
Unfortunately I'm not really getting this to work for me no matter how I try to modify it. I'm asking questions, the user is supposed to respond, and this system, while it shows that the text can be saved out, it just pulls everything, so it does not help me in the way I need. :(
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-19-2009 10:17
From: Ceera Murakami
Better version, that stores and uses the last reply it heard. Again, for the script to work, everywhere that there is a < symbol, remove the blank space after that symbol. The Forum filters wouldn't let me post the script without adding those spaces.
I'm pretty sure that you don't need to remove those spaces. They're absorbed by the lexical analyzer and never even get to the parser skeleton.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-19-2009 11:04
From: Argent Stonecutter
I'm pretty sure that you don't need to remove those spaces. They're absorbed by the lexical analyzer and never even get to the parser skeleton.

Confirmed.

I now have Indent set up so that it automatically adds the space after every angle bracket. Works fine in SL.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-19-2009 11:40
From: Jesse Barnett
Confirmed.

I now have Indent set up so that it automatically adds the space after every angle bracket. Works fine in SL.
Watch out for quoted text strings.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Ceera Murakami
Texture Artist / Builder
Join date: 9 Sep 2005
Posts: 7,750
08-21-2009 20:05
The hardest part with this would be dealing with responding to more than one person speaking within Chat range.

If there is only one detected, then after the first reply to the speaker, increment a counter so the next pass will ask and store the second question, and use a list to store the replies, rather than a single variable.

But if someone else speaks while you're interacting with the first person, you would need to either tell them to wait for you to indicate they are done with the first speaker, or would need to keep separate queues and increment variables for each person heard from.

I suppose you could do a list that records each person's Avatar Key as it hears them, followed by what they said, followed by the increment value. And then as you reply, search backwards in that list to get the previous reply incident and counter value matching that avatar key, so you could keep the counter going.

A matrix would be best here, but SL does not support matrices as storage arrays, only lists.

You could also set it up so that once it hears someone, it only replies to that person until it has asked and gotten replies for all its questions, or until a timer has elapsed and it assumes the original speaker has left or gone AFK.
_____________________
Sorry, LL won't let me tell you where I sell my textures and where I offer my services as a sim builder. Ask me in-world.
Kleston Axelbrad
Registered User
Join date: 27 Mar 2008
Posts: 23
08-21-2009 20:27
Well, it won't be listening on channel 0, it's something that will be one user at a time, not multiple people. So the listen will be for a set individual. I know that it's possible as one person in SL has created a product that does this function (FormTEC), but I've yet to hear a response from that individual in asking what kind of deal we could make for me to find out how he did it.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
08-22-2009 07:48
Grr.. I've done a solution for the OP and the damn thing won't post, despite there not being a single < angle bracket > in it. I can't track down what's causing the problem, either. Anyway, I had a look on xstreet at the item mentioned, and it's for doing questionnaires.

I've made a very basic example to show the logic of how I'd do it, and posted it at http://docs.google.com/Doc?docid=0AWKSp4VPA02sZGRrMmNrc3ZfMWdxYzRyamZr&hl=en

I've not done anything with the answer list, but it shouldn't be too difficult to make it email the results and clear the list every so often.

Hope this helps.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-22-2009 08:57
From: Innula Zenovka
I've made a very basic example to show the logic of how I'd do it, and posted it at http://docs.google.com/Edit?docid=ddk2cksv_1gqc4rjfk

You need to adjust access for the document Innula.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-22-2009 09:05
Here's your script Innula. Seems we have another filter in place. I had to add a space between = & bracket. Stooooooooopid LL webmaster!

CODE

list questions = ["What did you have for breakfast this morning?",
"What is your star sign?",
"Do you like pie?"];
string caption;
list answers;
list temp;
integer in_use;
integer counter;
integer listen_channel = 5;
integer dialog_channel = -15045;
integer handle;
integer max;
key av_id;

give_dialog(key av_id) {
handle = llListen(dialog_channel, "", av_id, "");
caption =
"Please click OK and then reply on channel " + (string) listen_channel + " to the following question:";
llDialog(av_id, caption + (string) (counter + 1) + " " + llList2String(questions, counter),["OK"],
dialog_channel);
llSetTimerEvent(20.0);
}

default {
state_entry() {

max = llGetListLength(questions);
}
touch_start(integer n) {
key toucher = llDetectedKey(0);
if (in_use == FALSE) { // no one's using me
in_use = TRUE;
counter = 0;
av_id = toucher;
give_dialog(av_id);
}
else if (in_use == TRUE) {
if (toucher != av_id) {
llInstantMessage(toucher, "Sorry, this is in use at the moment");
return;
}
else {
give_dialog(av_id);
}
}
}
timer() { // the av has got bored with the survey, so let's time out and reset
llSetTimerEvent(0.0);
llListenRemove(handle);
temp = [];
av_id = NULL_KEY;
in_use = FALSE;
}
listen(integer channel, string name, key id, string msg) {
if (channel == dialog_channel) {
llListenRemove(handle);
llSetTimerEvent(0.0);
handle = llListen(listen_channel, "", id, "");
}
else if (channel == listen_channel) {
llListenRemove(handle);
llSetTimerEvent(0.0);
answers += ["In reply to question " + (string) (counter + 1) + ", " + name + " said "];
answers += [msg];
temp += [msg];
++counter;
if (counter < max) {
give_dialog(id);
}
else {
for (counter = 0; counter < max; ++counter) {
llInstantMessage(id,
"In reply to the question, \"" + llList2String(questions,
counter) +
"\" you said, \"" + llList2String(temp, counter) + "\"");
}
temp = [];
av_id = NULL_KEY;
in_use = FALSE;
}
}
}
}

_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
08-22-2009 09:14
Thank you so much, Jesse
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
08-22-2009 13:19
I can't reproduce the error jesse cited... maybe i'm getting it wrong...

there was no spacing between = and [ characters casing it? like so..
temp=[];
???
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-22-2009 14:20
From: Void Singer
I can't reproduce the error jesse cited... maybe i'm getting it wrong...

there was no spacing between = and [ characters casing it? like so..
temp=[];
???
Space between syntactical elements is not meaningful to LSL.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-22-2009 14:30
From: Void Singer
I can't reproduce the error jesse cited... maybe i'm getting it wrong...

there was no spacing between = and [ characters casing it? like so..
temp=[];
???

Correction. As you pointed out in the other thread it was the older/new problem of no space after the opening angle bracket in two locations.

if (counter < max) {

for (counter = 0; counter < max; ++counter) {
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
08-22-2009 16:28
Arrgh.. of course.. i was thinking of angle brackets as what you have round vectors.. It just didn't occur to me that the signs for greater than and less than are the same thing.. stupid me!
Kleston Axelbrad
Registered User
Join date: 27 Mar 2008
Posts: 23
08-23-2009 12:37
From: Innula Zenovka
Grr.. I've done a solution for the OP and the damn thing won't post, despite there not being a single < angle bracket > in it. I can't track down what's causing the problem, either. Anyway, I had a look on xstreet at the item mentioned, and it's for doing questionnaires.

I've made a very basic example to show the logic of how I'd do it, and posted it at http://docs.google.com/Doc?docid=0AWKSp4VPA02sZGRrMmNrc3ZfMWdxYzRyamZr&hl=en

I've not done anything with the answer list, but it shouldn't be too difficult to make it email the results and clear the list every so often.

Hope this helps.


Perfect. That's the exact functionality I was looking for to be able to complete this project. Now I just need to compile it all together and move to the finalization steps. Thanks to all of you for your help.