Jump to content

I don't think this is how it's written


DarkEmperor13
 Share

You are about to reply to a thread that has been inactive for 2419 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hey I'm trying to get this script to work which brings up a dialog menu that when u choose an option, it gives u an item from prim inventory:

list buttons = ["Choice 1", "Choice 2", "Choice 3"];
string dialogInfo = "\nPlease make a choice.";
 
key ToucherID;
integer dialogChannel;
integer listenHandle;
 
default
{
    state_entry()
    {
        dialogChannel = -1 - (integer)("0x" + llGetSubString( (string)llGetKey(), -7, -1) );
    }
 
    touch_start(integer num_detected)
    {
        ToucherID = llDetectedKey(0);
        llListenRemove(listenHandle);
        listenHandle = llListen(dialogChannel, "", ToucherID, "");
        llDialog(ToucherID, dialogInfo, buttons, dialogChannel);
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if (message == "IL Ave.")
        {
            llDialog(ToucherID, dialogInfo, buttons, dialogChannel);
             llGiveInventory(llDetectedKey(0),"Illinois Ave.");
        }
 
        llListenRemove(listenHandle);
 
        if (message == "IN Ave.")
        {
            llDialog(ToucherID, dialogInfo, buttons, dialogChannel);
            llGiveInventory(llDetectedKey(0),"Indiana Ave.");
        }
 
        llListenRemove(listenHandle);
        
        if (message == "KY Ave.")
        {
            llDialog(ToucherID, dialogInfo, buttons, dialogChannel);
             llGiveInventory(llDetectedKey(0),"Kentucky Ave.");
        }
 
        llListenRemove(listenHandle);
        
        }
    }

I've tried to figure out how to make it work but for the life of me, that is not working for me. What am I missing or what am  I doin wrong?

Link to comment
Share on other sites

For one thing, your button labels are "Choice 1", "Choice 2", "Choice 3" but your listen event is listening for entirely different messages, which are never sent anywhere..

Then, you have a new llDialog statement each time that a message is received, but you've already closed the llListen by then, so the new Dialogs won't be heard.

Edited by Rolig Loon
Link to comment
Share on other sites

When you click a menu button, that causes your viewer to say the text on that button on whatever channel you've specified in the llDialog call.   So when someone clicks the button "Choice 1", the script hears the literal string "Choice 1" on dialogChannel (it's the one time avatars can speak on negative channels, at least in the Official Viewer).

So you need either to change the text on your buttons to read "IL Ave.", "KY Ave." and "KY Ave." OR to put in some if .. else if ... clauses in the listen event.   

Also, as Rolig says, you need to reopen the listener each time you present the user with a new menu.

Link to comment
Share on other sites

Ok nvm i understand now and got it working. Now my next problem is when i click on a button, let's say "IL Ave." for example, it will bring up the same buttons and if i press it again it gives me the item. How do i keep it from bringing up the dialog menu with the buttons twice?

Edited: NVM I figured it out. I had to remove the "llDialog(ToucherID, dialogInfo, buttons, dialogChannel);" part from each button's thingy whatever you call it.

Edited by DarkEmperor13
Link to comment
Share on other sites

5 minutes ago, DarkEmperor13 said:

Ok nvm i understand now and got it working. Now my next problem is when i click on a button, let's say "IL Ave." for example, it will bring up the same buttons and if i press it again it gives me the item. How do i keep it from bringing up the dialog menu with the buttons twice?

 

..because you have an extra llDialog call before each of your llGiveInventory calls. You can probably remove those (unless you had a purpose for them).

Link to comment
Share on other sites

Ugh... Now I'm getting an error again. Here i the code now(sorry for the third in a row post):

list buttons = ["IL Ave.", "IN Ave.", "KY Ave."];
string dialogInfo = "\nPlease make a choice.";
 
key ToucherID;
integer dialogChannel;
integer listenHandle;
 
default
{
    state_entry()
    {
        dialogChannel = -1 - (integer)("0x" + llGetSubString( (string)llGetKey(), -7, -1) );
    }
 
    touch_start(integer num_detected)
    {
        ToucherID = llDetectedKey(0);
        llListenRemove(listenHandle);
        listenHandle = llListen(dialogChannel, "", ToucherID, "");
        llDialog(ToucherID, dialogInfo, buttons, dialogChannel);
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if (message == "IL Ave.")
        {
            llListen(dialogChannel, "", ToucherID,"");
        }
            llGiveInventory(ToucherID, "Illinois Ave.");
        { 
        llListenRemove(listenHandle);
       
        if (message == "IN Ave.")
        {
            llListen(dialogChannel, "", ToucherID,"");
        }
            llGiveInventory(ToucherID, "Indiana Ave.");
        { 
        llListenRemove(listenHandle);
        if (message == "KY Ave.")
        {
            llListen(dialogChannel, "", ToucherID,"");
        }
            llGiveInventory(ToucherID, "Kentucky Ave.");
        { 
        llListenRemove(listenHandle);

        }
    }
}

It's saying the error is at the very last closed bracket. I tried deleting it and now its saying the error is at the closed bracket that was on top of the one i deleted.

Link to comment
Share on other sites

You have a bunch of extra “{“. Also, Why do you have an llListen() with each if() statement? Sorry, when I advised you to remove the extra llDialogs I didn’t notice those.

I believe your problem is that after each of your llGiveInventory() calls you have an extra { with no purpose. Also, your llListenRemove calls are not in the if {} block. Here is the pattern I think you intend - did you ever consider using “else if”? :

if (msg==“xx”) {

  llGiveInventory(..);

  llListenRemove(..);

}

else if (msg==“xx”) {

  llGiveInventory(..);

  llListenRemove(..);

}

Etc.

Link to comment
Share on other sites

I don't understand the point of opening and immediately closing the listeners inside the listen event.

If the idea is to keep on presenting the user with a menu, then I would call llSetTimerEvent in the touch_start event, and then again in the listen event.    And I would use the timer event, when it finally fires, to close things down.  Like this (this is just a fragment, obviously)

    timer(){
        //not heard anything for 30 seconds, so the user is probably finished.  Time out, anyway
        llSetTimerEvent(0.0);//stop timer
        llListenRemove(listenHandle);
    }
 
    listen(integer channel, string name, key id, string message)
    {
        llSetTimerEvent(30.0);//restart the timer, to keep the listener open
        if (message == "IL Ave.")
        {
           llGiveInventory(ToucherID, "Illinois Ave.");
        }
            
    //    { 
    //    llListenRemove(listenHandle);
       
       else if (message == "IN Ave.")
        {
            llGiveInventory(ToucherID, "Indiana Ave.");
        }
            
      //  { 
      //  llListenRemove(listenHandle);
       else if (message == "KY Ave.")
        {
           llGiveInventory(ToucherID, "Kentucky Ave.");
        }
            
        llDialog(ToucherID, dialogInfo, buttons, dialogChannel);
    }

ETA:  You could simplify it (and add a "Finished" option so the user can dismiss the menu and turn off the listener), by doing something like this

    touch_start(integer num_detected)
    {
        ToucherID = llDetectedKey(0);
        llListenRemove(listenHandle);
        listenHandle = llListen(dialogChannel, "", ToucherID, ""); //reopen the listener
        llDialog(ToucherID, dialogInfo, buttons + ["Finished"], dialogChannel);//represent the menu
        llSetTimerEvent(30.0);

    }

    timer(){
        //not heard anything for 30 seconds, so the user is probably finished.  Time out, anyway
        llSetTimerEvent(0.0);//stop timer
        llListenRemove(listenHandle);
    }
 
    listen(integer channel, string name, key id, string message)
    {
        llSetTimerEvent(0.0);//stop timer
        llListenRemove(listenHandle);//turn off listener
        list lItems =[//list of items *in same order as the list of menu buttons*
        "Illinois Ave.",
        "Indiana Ave.",
        "Kentucky Ave."
        ];
        integer n = llListFindList(buttons, [message]);//get the index number of the message
        if(~n){//if the message is in the list of menu buttons, and not "Finished"
            string str = llList2String(lItems,n);//find the corresponding entry in lItems
            if(llGetInventoryType(str)!=INVENTORY_NONE){//if str is an item in the object's inventory
                llGiveInventory(ToucherID, str);//give it to the user
                listenHandle = llListen(dialogChannel, "", ToucherID, ""); //reopen the listener
                llDialog(ToucherID, dialogInfo, buttons + ["Finished"], dialogChannel);//represent the menu
                llSetTimerEvent(30.0);
            }

        }
        
    }

NB Change to my ETA example (this is what happens when I copy paste stuff when I'm tired)

Edited by Innula Zenovka
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2419 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...