Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dialog Example

Parsalin Gullwing
The big PG
Join date: 16 Aug 2004
Posts: 32
01-09-2005 07:32
Well, i looked around and didnt find anything in here on this so i went to the wiki and figured it out :) so here is an example of how an lldialog works :)

CODE
// when touched, present a dialog with four color choices

integer CHANNEL = 42; // dialog channel
default {
state_entry() {
llListen(CHANNEL, "", llGetOwner(), ""); // listen for the dialog answer
}

touch_start(integer total_number) {
if (llGetOwner() != llDetectedKey(0)) return;
llDialog(llGetOwner(), "Choose a color", ["Red", "Green", "Blue", "Pink"], CHANNEL); // ask a question
}
listen(integer channel, string name, key id, string message) {
if(message == "Pink"){
llSay(0, "Pink");
}
else{
llSay(0, "Not Pink?");
}
llSay(0, llKey2Name(id) + " picked the color " + llToLower(message) + "."); // output the answer
llResetScript();
}

}


It also shows how you could use it to perfor another action based on what they choose using an if!

Discussion Thread
/54/51/166230/1.html
Racer Plisskin
Rezerator
Join date: 2 Jan 2005
Posts: 147
01-17-2005 04:00
Hmm.... I don't think so. (Sorry)

The function above does not solve the basic problem of accomplishing a simultaneous move/rotate. Your code is still a sequential move-rotate or if a few lines are reordered, a rotate-move.

It does not solve the basic problem of achieving a single motion animation of a rotation of a prim around an offset center point.

Here's my original code that basicaly does the same thing the function above does and that I was looking to replace with something that would produce a smoother animation.

CODE
integer has_moved;
vector prim_mov;
rotation prim_rot;

// Object to be rotated
// Prims initial vector and rotation
vector position_A = <0.295746, 0.995255, 0.319721>;
rotation rotation_A = <1.0, 0.0, 0.0, 0.0>;

// Prims destination vector and rotation
vector position_B = <0.556702, 0.995255, 1.222816>;
rotation rotation_B = <-0.819152, 0.0, 0.573576, 0.0>;

default
{
state_entry()
{
// Assume object has not moved to start with...
has_moved = FALSE;

// The prims vector and rotation changes based on the above raw data...
prim_mov = position_B - position_A;
prim_rot = rotation_B - rotation_A;
}

touch_start(integer n)
{
if (llDetectedKey(0) == llGetOwner())
{
if (has_moved)
{
llSetRot(llGetLocalRot() + prim_rot );
llSetPos(llGetLocalPos() - prim_mov );
has_moved = FALSE;
}
else
{
llSetPos(llGetLocalPos() + prim_mov );
llSetRot(llGetLocalRot() - prim_rot );
has_moved = TRUE;
}
}
}
}

The goal is to replace the 2 commands (llSetPos & llSetRot) with a single command or function that would produce a mov/rot in a sigle motion, not two discrete motions.

Thanks for the effort though.

Racer P.
Lance Hedges
Brian Peppers!!
Join date: 23 May 2004
Posts: 151
01-19-2005 14:40
Yay soemthnig else to play with, thanks.
_____________________
Walker Spaight
Raving Correspondent
Join date: 2 Jan 2005
Posts: 281
01-29-2005 08:28
I recently built myself a doorbell using llDialog. If someone rings the doorbell, it llDialogs with me, telling me who's at the door and asking whether I want to "Let In", "Send Away" or "Ignore". Depending on my response, it sends a link_message to the door itself, which opens or closes accordingly. The great thing about it is, I get the llDialog wherever I am on the grid. At some point I'll build in an escape to handle situations when I'm not logged on (I think the llDialog just doesn't execute if the key it's aimed at isn't on the grid), but it was a neat use of llDialog, I thought. I'll post it here when I get a chance, if anyone's interested.
Walker Spaight
Raving Correspondent
Join date: 2 Jan 2005
Posts: 281
01-29-2005 09:57
I recently wrote a pair of scripts that put a doorbell on my house in Louise. When someone rings the bell, llDialog tells me who's at the door and asks whether I want to "Let in", "Send away", or "Ignore". What's nice is that I get the dialog anywhere on the grid. It needs a patch to handle occasions when I'm not logged in, but it struck me as a nifty use of llDialog when I was writing it.

CODE
// this first script goes in the root object of a 2-prim set
// the door itself is the child
// I haven't tested it on objects with more than two prims, but it should work
// the doorbell llDialogs with owner, then allows entry based on response
// sends link_message to door prim based on llDialog
// currently llDialogs whether or not owner is home or away or on or off line
// by Walker Spaight, January 2005

// global variables
integer gChannel = 123; // llDialog channel of your choice
integer gLinkedDoor = 2; // linknum of door prim
key gOwnerKey; // key of doorbell owner
string gFloaty = "ring doorbell for entry\n \n"; // floaty text
string gOpenMsg = "open door"; // open message to door prim
string gCloseMsg = "close door"; // close message to door prim

//---------|color vectors - DON'T CHANGE|----------//
vector red = <1,0,0>;
vector green = <0,1,0>;
vector blue = <0,0,1>;
vector white = <1,1,1>;
vector black = <0,0,0>;
vector yellow = <1,0,1>;
//-------------------------------------------------//

// initialize
init()
{
llSetText (gFloaty, red, 2);
gOwnerKey = llGetOwner();
} // end init

// ring the doorbell
ringBell(string ringer)
{

// bell sound would get played here, mine isn't installed at the moment
llDialog (gOwnerKey, ringer + " is at the door.", [ "Let in", "Send away" ], gChannel);
llListen (gChannel, "", "", "");
} // end ringBell

default
{
state_entry()
{
init();
} // close state_entry

touch_start(integer total_number)
{
string name; // name of avatar at the door

name = llDetectedName(0);
ringBell(name);
} // close touch_start

// handles listen for let in/send away, the llDialog response
listen (integer channel, string nm, key id, string message)
{
integer num;
if ((channel == gChannel) && (message == "Let in"))
{
llMessageLinked (gLinkedDoor, num, gOpenMsg, gOwnerKey);
}
else if ((channel == gChannel) && (message == "Send away"))
{
llSay(0, "You may not enter at this time.");
}
} // close listen

} // close default
// end of first script



CODE
// the second script goes in the door itself and performs the open/close op
// based on response to llDialog
// also allows for voice commands on a closed channel
// since my current door is a manhole cover, opening it just consists of
// making it more transparent by changing the alpha value
// and setting it to Phantom
// by Walker Spaight, January 2005

// global variables
float gTransVal = 0.2; // alpha value for open state
float gOpaque = 1.0; // alpha value for closed state
integer gVoice = 789; // channel for voice commands
key gOwnerKey; // key of doorbell owner
string gDoorStatus; // is door "open" or "closed"
string gOpenCmd = "open door"; // command that opens door
string gCloseCmd = "close door"; // command that closes door

// initialize
init()
{
gOwnerKey = llGetOwner();
gDoorStatus = "closed";
llSetAlpha(1.0, ALL_SIDES);
llSetStatus(STATUS_PHANTOM, FALSE);
} // end init

// open or close the door
doDoor(string command)
{
if (command == gOpenCmd)
{
if (gDoorStatus == "open")
{
llWhisper(0, "The door is already open.");
}
else // open the door
{
// replace this with your favorite rotation routine if it's a regular door
llSetAlpha(gTransVal, ALL_SIDES);
llSetStatus(STATUS_PHANTOM, TRUE);
llWhisper(0, "The door is now open.");
gDoorStatus = "open";
}
} // end gOpenCmd routine
else if (command == gCloseCmd)
{
if (gDoorStatus == "closed")
{
llWhisper(0, "The manhole is already closed.");
}
else // close the door
{
// replace this with your favorite rotation routine if it's a regular door
llSetAlpha(gOpaque, ALL_SIDES);
llSetStatus(STATUS_PHANTOM, FALSE);
llWhisper(0, "The manhole is now closed.");
gDoorStatus = "closed";
}
} // end gCloseCmd routine
} // end doDoor

default
{
state_entry()
{
init();

// set listen for a voice command to open or close the door
llListen(gVoice, "", "", gOpenCmd);
llListen(gVoice, "", "", gCloseCmd);
} // end state_entry

// called if the door receives a message from a linked prim, i.e., the doorbell
link_message(integer sender_num, integer num, string str, key id)
{
doDoor(str);
} // end link_message

// called if voice command received
listen (integer channel, string name, key id, string msg)
{
if ((id == gOwnerKey) && (channel == gVoice))
{
doDoor(msg);
}
} // end listen
} // end default

edits - Added a ';' in the first script, line 10. Changed gChannel in line 83 to gVoice. Now these scripts should work fresh out of the box. - ne
Patti Frye
Registered User
Join date: 25 Aug 2006
Posts: 60
02-06-2007 18:19
I tried the first script and got an error on Line 10, Column 0.
I'm not a scripter so I don't know what the problem is.