Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Why Doesn't this work?

Dudeney Ge
EduNation Archipelago
Join date: 21 Jul 2006
Posts: 95
08-15-2006 04:00
Hi,

I'm just getting started on a small menu driven notecard giver (for various reasons too boring to mention). Wondering why this refuses to deliver the notecard if the first menu item is chosen (card is in the prim inventory and named correctly). Thanks in advance for any assistance.


[ SAMPLE BEGINS HERE ]

integer dialog_channel= 427; // set a dialog channel
list menu = [ "Menu1", "Menu2" ];
default
{
state_entry()
{
// arrange to listen for dialog answers (from multiple users)
llListen( dialog_channel, "", NULL_KEY, "";);
}

touch_start(integer total_number)
{
llDialog( llDetectedKey( 0 ), "make a choice", menu,
dialog_channel );
}

listen(integer channel, string name, key id, string choice )
{
vector position = llGetPos();

// if a valid choice was made, implement that choice if possible.
// (llListFindList returns -1 if choice is not in the menu list.)
if ( llListFindList( menu, [ choice ]) != -1 )
{
if ( choice == "Menu1" )
{
llGiveInventory(llDetectedKey(0),"Getting Started";);
}
else if( choice == "Menu2" )
{
llSay(0, "you chose Menu2";);
}
}
else
{
llSay( 0, "Invalid choice: " + choice );
}
}
}
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
08-15-2006 04:46
From: Dudeney Ge
listen(integer channel, string name, key id, string choice )
{
vector position = llGetPos();

// if a valid choice was made, implement that choice if possible.
// (llListFindList returns -1 if choice is not in the menu list.)
if ( llListFindList( menu, [ choice ]) != -1 )
{
if ( choice == "Menu1" )
{
llGiveInventory(llDetectedKey(0),"Getting Started";);
You can't set llDetectedKey under listen event. ;)
_____________________
:) Seagel Neville :)
Dudeney Ge
EduNation Archipelago
Join date: 21 Jul 2006
Posts: 95
Thanks for the info, but...
08-15-2006 05:01
Hi,

And thanks for that - so how do I get it to deliver the notecard on button press?

DG
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
08-15-2006 05:11
What about replacing id which is difined in parenthesis of listen event for llDetectedKey(0)?
_____________________
:) Seagel Neville :)
Dudeney Ge
EduNation Archipelago
Join date: 21 Jul 2006
Posts: 95
Still no joy
08-15-2006 05:51
Hi,

I really appreciate your answers. I'm new to all this and it's not making a lot of sense. I just really wanted a menu-driven notecard dispenser, but can't quite get it to work. I can get the choice button to speak something, but can't work out how to get it to give something out to the person asking for it.

DG
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
08-15-2006 05:56
See this line?
CODE
llGiveInventory(llDetectedKey(0),"Getting Started");

That gives the avatar with the key llDetectedKey(0) the notecard called "Getting Started". But in your script, llDetectedKey(0) has no value, because it only has a value in certain events like touch_start and sensor, not listen. (Makes no sense, yes, I know, it would be good for it to be consistent, but it isn't.)

See this line?
CODE
listen(integer channel, string name, key id, string choice )

That means that, during your listen event, the key of whoever you're listening to goes into the variable id. So you want to give the card to the avatar with that key instead.
Dudeney Ge
EduNation Archipelago
Join date: 21 Jul 2006
Posts: 95
Thanks
08-15-2006 06:01
Ordinal,

Thanks - finally got there. And thanks to Seagel for sending me a working version along those lines too.

DG