Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dialog Timeout?

Keno Pontoppidan
Registered User
Join date: 20 Oct 2005
Posts: 75
12-20-2006 09:31
How would I create a timeout for a dialog if it dosent get a response after a while so the listen can turn off?
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
12-20-2006 09:42
If you save handle returned by llListen(), then you can set your own timer to remove the listener after a period of time.

However, there is no way to actually dismiss the dialog box itself. A button press after the listener has been removed simply gets ignored.

I urge scripters to vote for Proposal 2448.

While the original proposal was to add text-input field to llDialog -- which is badly needed in itself -- its corresponding discussion thread includes several ideas on extending the llDialog system including the ability to dismiss dialogs.

-peekay
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
12-20-2006 12:18
Here's an example free of off-topic campaigning :D

CODE
// Dialog Timeout Example Script by Boss Spectre

integer TIMEOUT = 30; // seconds to wait for response
integer channel = -123; // could be randomized for general use
integer lHandle; // stored listen handle
integer waiting = FALSE; // TRUE if waiting for input
key user; // stores who we are wauting for if waiting
list buttons = [ "No", "Yes", "Whatever" ]; // dialog button list


clean_up()
{
// clean up to wait for another click
llSetTimerEvent(0);
llListenRemove(lHandle);
user = NULL_KEY;
waiting = FALSE;
}

default
{
listen(integer channel, string name, key id, string message)
{
integer response = llListFindList(buttons, [message]); // look up the response

if (response >= 0) { // a match was found
llInstantMessage(id, "You chose #" + (string)(response + 1) + " (" + message + ")");
clean_up();
}
}

touch_start(integer total_number)
{
if (waiting) {
if (llDetectedKey(0) != user)
{
llInstantMessage(llDetectedKey(0),
"Sorry, someone else is using me, try again later.");
return;
}
// fall through and repeat dialog for same user in case they hit ignore
}

user = llDetectedKey(0);
waiting = TRUE;

llListenRemove(lHandle);
lHandle = llListen(channel, "", user, "");

llDialog(user,
"You have " + (string)TIMEOUT + " seconds to respond.", buttons, channel);

llSetTimerEvent((float)TIMEOUT);
}

timer()
{
llInstantMessage(user, "Time's up, click again to start over.");
clean_up();
}
}

I hope it's helpful.