Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with a Menu

Taron Ling
Registered User
Join date: 3 Mar 2007
Posts: 3
07-26-2007 14:03
I made a box when you click it it opens a Menu when you click on take candy it should hand you the object, it orks fine as long as i use llGetOwner() in the script but then only i can get the candy, i want it so everyone can take it i tried llDetectedKey(0) but then all i get are 2 errors and it wont work at all anymore.
Dina Vanalten
Registered User
Join date: 24 Dec 2006
Posts: 268
07-26-2007 14:24
Can you post your code so we can see what's happening please. Its a bit hard to debug from just a description. Thanks.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
Help us to help you......
07-26-2007 14:25
From: Taron Ling
I made a box when you click it it opens a Menu when you click on take candy it should hand you the object, it orks fine as long as i use llGetOwner() in the script but then only i can get the candy, i want it so everyone can take it i tried llDetectedKey(0) but then all i get are 2 errors and it wont work at all anymore.



Try Posting the code to give us at least a chance of helping you.
what are the errors?
_____________________
I'm back......
Taron Ling
Registered User
Join date: 3 Mar 2007
Posts: 3
07-26-2007 14:30
This is the script i currently have in the box it works perfectly fine i you leave it with just llGetOwner() but then not everyone can take the objects.

integer dialog_channel= 450; // set a dialog channel
list menu = [ "Inspect", "Take Candy" ];

default
{
state_entry()
{
llListen( dialog_channel, "", NULL_KEY, "";);
}

touch_start(integer total_number)
{
llDialog( llDetectedKey( 0 ), "Select from the below Options?", menu, dialog_channel );
}

listen(integer channel, string name, key id, string choice )
{

if ( llListFindList( menu, [ choice ]) != -1 )
{
if ( choice == "Inspect" )
{
llSay(0, "As you take a closer look at the wooden box, you can see a text on the top reading Sura's Candy Box.";);
}
}
if( choice == "Take Candy" )
{
list inventory;
string name;
integer num = llGetInventoryNumber(INVENTORY_OBJECT);
string text = " Searching Box...\n";
integer i;
key user = llDetectedKey(0);

for (i = 0; i < num; ++i) {
name = llGetInventoryName(INVENTORY_OBJECT, i);
if(llGetInventoryPermMask(name, MASK_OWNER) & PERM_COPY)
inventory += name;
else
llOwnerSay("Cannot give asset \""+name+"\", owner lacks copy permission";);
llSetText(text + (string)((integer)(((i + 1.0) / num) * 100))+ "%", <1, 1, 1>, 1.0);
}

text = llGetObjectName();

i = llListFindList(inventory, [llGetScriptName()]);
if(~i)//if this script isn't found then we shouldn't try and remove it
inventory = llDeleteSubList(inventory, i, i);

if (llGetListLength(inventory) < 1) llSay(0, "The Box is Empty no Candy left.";); else
{
llGiveInventoryList(user, text, inventory);
llSetText("The Box is slightly open seems\nlike someone stoled some of your Candy!",<1,1,1>,1);
name = "Your new "+ text +" can be found in your inventory, in a folder called '"+ text +"'. ";
if(user == llGetOwner())
llOwnerSay(name);
else
llInstantMessage(user, name);
}
}
}
}
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
07-26-2007 15:01
add this:


on_rez ()
{
llResetScript();
}


When you first run a script, the owner (the creator all cases), is read, and that is information is saved. The llGetOwner() is actually only done once. To force the script to re-read the owner each time it's ran, you need to reset the script. Putting the reset in the on_rez statement will cure your problem. Be sure to do this with any scripts you write that use llGetOwner().
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
07-26-2007 15:17
I'm guessing this is the problem line:

key user = llDetectedKey(0);

In the listen Event Handler, llDetectedkey isn't going to work. Luckily, the listen Event Handler is carrying the key as 'id'... so:

key user = id;

...should help (or just discard the 'user' variable and use 'id').


As an aside llGetOwner() will work whenever it is requested - not just when a script is first run. The problem arises when a script relies on having requested llGetOwner in the state_entry Event Handler, which does run only once when a state is entered. Which might be only when the script is reset/compiled.
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
07-26-2007 15:19
key user = llDetectedKey(0);

should read:

key user = id;


The touch event can use llDetectedKey() as you did, but when you call a dialog with that ID, it raises the dialog on that users screen. So far so good. When they actually click a button, you get a listen as though they did an llSay() of the text on that button.

The listen() event provides the id of the speaker, that is what you are looking for.

That is without looking too close at the permissions stuff, but this is certainly a place to start.
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
07-26-2007 15:20
Hah, or what Pale said.