Jump to content

trying to add "owner only" access to a menu


Faye Mercury
 Share

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

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

Recommended Posts

hello, ive bumped into a little issue while trying to modify a free script, im just trying to add a menu that lets you change the texture when touched. the script is perfect, except i want it to be owner only. when i added the following line under the "touch_start" line, i received an error saying that it wasnt defined.

if (llDetectedKey(0) == llGetOwner())

 

i believe it had something to do with the integers although i have no clue how this works. that or i did something stupid! here is the current script (which does work as-is):

list MENU1 = [];
list MENU2 = [];
integer listener;
integer MENU_CHANNEL = 1000;
 
// opens menu channel and displays dialog
Dialog(key id, list menu)
{
    llListenRemove(listener);
    listener = llListen(MENU_CHANNEL, "", NULL_KEY, "");
    llDialog(id, "Select one object below: ", menu, MENU_CHANNEL);
}
 
default
{
    on_rez(integer num)
    {
        // reset scripts on rez
        llResetScript();
    }
    
    touch_start(integer total_number)
    {
        integer i = 0;
        MENU1 = [];
        MENU2 = [];
        // count the textures in the prim to see if we need pages
        integer c = llGetInventoryNumber(INVENTORY_TEXTURE);
        if (c <= 12)
        {
            for (; i < c; ++i)
                MENU1 += llGetInventoryName(INVENTORY_TEXTURE, i);
        }
        else
        {        
            for (; i < 11; ++i)
                MENU1 += llGetInventoryName(INVENTORY_TEXTURE, i);
            if(c > 22)
                c = 22;
            for (; i < c; ++i)
                MENU2 += llGetInventoryName(INVENTORY_TEXTURE, i);
            MENU1 += ">>";
            MENU2 += "<<";                          
        }
        // display the dialog
        Dialog(llDetectedKey(0), MENU1);
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if (channel == MENU_CHANNEL)
        {
            llListenRemove(listener);  
            if (message == ">>")
            {
                Dialog(id, MENU2);
            }
            else if (message == "<<")
            {
                Dialog(id, MENU1);
            }        
            else                    
            {
                // display the texture from menu selection
                llSetTexture(message, ALL_SIDES);
 
            }      
        }
    }  
}

 

i have very limited coding knowledge and no practice with LSL, so any help is appreciated! thanks!

 

Link to comment
Share on other sites

I suspect the line was added right after touch_start, it would be best positioned after the MENU2=[]; statement.

Immediately after the line if( llDetectedKey(0) == llGetOwner()) there needs to be a curly bracket

 

{

and then at the end of the touch_start event,  after the call to Dialog(), there needs to be a closing curly bracket

}

Link to comment
Share on other sites

4 minutes ago, Rolig Loon said:

llDetected* functions can only be used in events that actually detect something., specifically  the touch*, collision*, and sensor events. If you put them in the state_entry event, they won't know what to do.  

thanks for the response. but can you elaborate on this? i did put it under the 'touch_start" bracket per instruction from some previous threads about owner only menus and quick wiki searches. i did something like this:

touch_start(integer total_number)
    {
		if (llDetectedKey(0) == llGetOwner())
        integer i = 0;
        MENU1 = [];
        MENU2 = [];
        // count the textures in the prim to see if we need pages
        integer c = llGetInventoryNumber(INVENTORY_TEXTURE);
        if (c <= 12)
        {
            for (; i < c; ++i)
                MENU1 += llGetInventoryName(INVENTORY_TEXTURE, i);
        }

 

Link to comment
Share on other sites

4 minutes ago, Faye Mercury said:

thanks for the response. but can you elaborate on this? i did put it under the 'touch_start" bracket per instruction from some previous threads about owner only menus and quick wiki searches. i did something like this:

 

Close! Do this at the same place instead:

touch_start(integer total_number)
{
  if (llDetectedKey(0) != llGetOwner()) return;
  integer i = 0;
  MENU1 = [];
  MENU2 = [];
  // count the textures in the prim to see if we need pages
  integer c = llGetInventoryNumber(INVENTORY_TEXTURE);
  if (c <= 12)
  {
    for (; i < c; ++i)
      MENU1 += llGetInventoryName(INVENTORY_TEXTURE, i);
}

In English, that would mean "If the detected key is not the owner, stop."

What you had before was kind of an incomplete piece of code, and it was confusing the script.

Edited by Wulfie Reanimator
  • Like 3
Link to comment
Share on other sites

Yes, but as written, it will only affect the line immediately after that if statement.  You want it ti apply to everything in the event, so you need to write

touch_start(integer total_number)

{

    if (llDetectedKey(0) == llGetOwner())

    {

           then every single thing that's already in the touch_start event, and then

    }

}

Brackets are important. 

EDIT: Or do what Wulfie suggested.  :) 

Edited by Rolig Loon
Link to comment
Share on other sites

5 minutes ago, Wulfie Reanimator said:

Close! Do this at the same place instead:


touch_start(integer total_number)
{
  if (llDetectedKey(0) != llGetOwner()) return;
  integer i = 0;
  MENU1 = [];
  MENU2 = [];
  // count the textures in the prim to see if we need pages
  integer c = llGetInventoryNumber(INVENTORY_TEXTURE);
  if (c <= 12)
  {
    for (; i < c; ++i)
      MENU1 += llGetInventoryName(INVENTORY_TEXTURE, i);
}

In English, that would mean "If the detected key is not the owner, stop."

this worked, thank you!

now if i can go back to figure out why it works, i have to admit trying to read and follow these step-by-step isnt unlike solving a puzzle for me haha. thank you everyone for your responses they were all very helpful 😃

Link to comment
Share on other sites

22 minutes ago, Faye Mercury said:

now if i can go back to figure out why it works,

 The magic line in wolfie's example is:

if (llDetectedKey(0) != llGetOwner()) return;

Early returns can be a bit hard for some people to read, but I personally prefer them to wrapping the entirety of the following code in a separate scope. the magic word 'return' is "normally" used in a function call to return a value after the function is called, like so:

integer double(integer i)
{
  return (i*2);
}
default
{
  touch_start(integer n)
  {
    llOwnerSay("twice 5 is:"+(string)double(5));
  }
}

but as well as returning a value it stops execution of the function it's in, because the function has 'done its job' and returned the answer.

when you use return in an event, nothing after the return is executed:

default
{
    touch_start(integer i)
    {
        return;
        llOwnerSay("You will never read this.");
    }
}

you can sometimes use an early return like this instead of an else clause:

default
{
  touch_start(integer i)
  {
    if(llDetectedKey(0)!=llGetOwner())
    {
      llSay(0,"You are not my owner!");
    }else
    {
      llSay(0,"You are my owner.");
      /*large block of code
      .
      .
      .
      */
    }
  }
}

could instead be written as:

default
{
  touch_start(integer i)
  {
    if(llDetectedKey(0)!=llGetOwner())
    {
      llSay(0,"You are not my owner!");
      return;
    }
    
    llSay(0,"You are my owner.");
    /*large block of code
    .
    .
    .
    */
    
  }
}

whether you use one or the other depends on your preferred style, and the situation.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1110 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...