Jump to content

Need help with linkset, that gives object when 1 of 6 child prims are touched and not root


Glovercali
 Share

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

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

Recommended Posts

Hello!

I have a box of chocolates

  • root prim is the the box - link 1
  • child prims are ONE kind of chocolate - links 2 - 8
  • last child prim is also the top, which opens to reveal the chocolates - link 9

So far I've managed to get the top working independently when clicked and the clicked chocolate to give 1 chocolate from box's inventory to avatar.

My issue is the box. It's the root prim and turns invisible when clicked and give a chocolate. This isn't my intention and not sure how to exclude this from the script I have here.

 

default

   
{
    touch_start(integer num_detected)
    {
        key user = llDetectedKey(0);
         
        
         llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN, [PRIM_LINK_TARGET,
         llDetectedLinkNumber(0), PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 0.0]);
         llGiveInventory(user, llGetInventoryName(INVENTORY_OBJECT, 0) );
       
    }
}

 

To clarify a bit -

When you click a chocolate (link 2 - 7 ) it is taken from the box (disappears) then delivers a chocolate from the objects inventory to the avatar's inventory. The chocolate says gone(which is intended) but if you accidently touch the BOX, it disappears as well and also gives a chocolate from inventory.

Please help! I'm still new to scripting and I sometimes miss things.

Edited by Glovercali
Link to comment
Share on other sites

  • Glovercali changed the title to Need help with linkset, that gives object when 1 of 6 child prims are touched and not root

Use an if statement to test for link number 1, and if it's so don't do anything.

One way would be to put the test at the start of the touch_start event and quit the event, doing nothing, if the link number is 1:

if (llDetectedLinkNumber (0) == 1) return;

Given that there's also another special case, link 9, the top, maybe some if/else statements might work better for you:

if (llDetectedLinkNumber (0) == 1)
{
    return; //do nothing
}
else if (llDetectedLinkNumber (0) == 9)
{
    //open the box
}
else
{
    //give a chocolate
}

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

'nother alternative :P

 integer link =  llDetectedLinkNumber(0);
 if(  link > 1 && link < 10 )
 {   llSetLinkPrimitiveParamsFast( link, [ 
        PRIM_COLOR, ALL_SIDES, <1.0, 1.0, 1.0>, 0.0]);
    llGiveInventory(user, llGetInventoryName(INVENTORY_OBJECT, 0) );
 }

 

Edited by Xiija
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

okay I tried both scripts, both work great!

Now my issue is when they click the chocolate, it disappears as intended but they click the alpha'd chocolate again and it gives another chocolate. I did add a usages to it which works great, once the uses are all used up, the box stops giving chocolate as intended 

its just the chocolates will continue to give you more chocolate, even though the prim is alpha'd and its not intended to do so. It will continue until the uses are finished off.

How do I prevent the alpha'd chocolate prim to stop giving chocolates from inventory, once it has already given one?

Edited by Glovercali
Link to comment
Share on other sites

14 minutes ago, Glovercali said:

okay I tried both scripts, both work great!

Now my issue is when they click the chocolate, it disappears as intended but they click the alpha'd chocolate again and it gives another chocolate. I did add a usages to it which works great, once the uses are all used up, the box stops giving chocolate as intended 

its just the chocolates will continue to give you more chocolate, even though the prim is alpha'd and its not intended to do so. It will continue until the uses are finished off.

How do I prevent the alpha'd chocolate prim to stop giving chocolates from inventory, once it has already given one?

That's a perfect use-case for an integer bitmask

integer is_taken;

state_entry()
{  is_taken = (1<<1)|(1<<9); // links 1 and 9 do not give out candies.
}
touch_start(integer n)
{
  integer link =  llDetectedLinkNumber(0);
  if( !(is_taken&(1<<link)) )
  {  is_taken = is_taken|(1<<link);
     // take the candy from link
     //...
  }
}

 

Edited by Quistess Alpha
  • Like 2
Link to comment
Share on other sites

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