Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Problem with simple menu-driven inventory giver

Rock Ryder
Registered User
Join date: 6 Oct 2006
Posts: 384
12-04-2007 05:28
Hi guys,

I wrote a little menu-driven landmark giver, which just refuses to work. I have tried both varieties of naming the landmark in llGiveInventory, and neither work, yet on their own within a touch-event (without the menu) they work fine. The strange thing is, if I rename the name of the landmark in the script (to something like 'Sweya' it DOES raise an error to say it can't find it, and doesn't raise an error when spelt correctly, so why (if it can find it) does it not give it? Can anyone see where I am going wrong here?

TIA

Rock


CODE

integer channel = 4913;

default
{
state_entry()
{
llListen(channel, "", NULL_KEY, "");
llSetText("Full?\nClick me", <0.9,0.7,0.586>, 1);
}

touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "If we are full then IM Ryuu Rosca, Rock Vacirca, or Rock Ryder, and we will be pleased to let you know when a SkyHome becomes available so we can arrange a viewing for you.\n\nOr why not visit our associate sim of Swey with its beautiful SkyHomes in a tropical setting.", [ "Landmark"], channel);
}

//The name of the landmark in the Contents is 'Swey'

listen(integer channel, string name, key id, string message)
{
if (message == "Landmark")
{
//llGiveInventory(llDetectedKey(0), "Swey");
llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_LANDMARK, 0));
}
else
{
llSay(0, message);
}
}
}
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
12-04-2007 05:42
The Problem is, that you're giving the Landmark withouth knowing the ID of the clicker :)

change this:

llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_LANDMARK, 0));

to this:

llGiveInventory(id, llGetInventoryName(INVENTORY_LANDMARK, 0));

the «id» comes from:

listen(integer channel, string name, key id, string message)

when the user clicks on the «Landmark»-Button, his/hers ID is passed to the listen-event

HTH
Rock Ryder
Registered User
Join date: 6 Oct 2006
Posts: 384
12-04-2007 06:01
From: Haruki Watanabe
The Problem is, that you're giving the Landmark withouth knowing the ID of the clicker :)

change this:

llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_LANDMARK, 0));

to this:

llGiveInventory(id, llGetInventoryName(INVENTORY_LANDMARK, 0));

the «id» comes from:

listen(integer channel, string name, key id, string message)

when the user clicks on the «Landmark»-Button, his/hers ID is passed to the listen-event

HTH


Many thanks, that fixed it.

:)
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
12-04-2007 07:38
Your code is a good example of bad coding... it should be done more like this...



integer channel = 4913;
integer listenHandle;
key avKey;
string menuMessage = "If we are full then IM Ryuu Rosca, Rock Vacirca, or Rock Ryder, and we will be pleased to let you know when a SkyHome becomes available so we can arrange a viewing for you.\n\nOr why not visit our associate sim of Swey with its beautiful SkyHomes in a tropical setting.";
list buttons = ["Landmark"];
integer channel = 4913;

default
{
state_entry()
{
llSetText("Full?\nClick me", <0.9,0.7,0.586>, 1);
}

touch_start(integer total_number)
{
listenHandle = llListen (channel, "", NULL_KEY, "";); // <-- dont put in state_entry if you can help it, use a handle so we can remove it later.
avKey = llDetectedKey (0);
llDialog(avKey, menuMessage, buttons, channel); <-- define variables.. call functions from the variables...
}

//The name of the landmark in the Contents is 'Swey'

listen(integer channel, string name, key id, string message)
{
if (message == "Landmark";)
{
llGiveInventory(llDetectedKey(0),llGetInventoryName (INVENTORY_LANDMARK, 0));
}
else
{
llSay(0, message); // <--- guessing this was a debug msg??? remove if so...
}
llListenRemove (listenHandle); // <--- no more menu, remove listen, will turn back on on next touch
}
}