Jump to content

Ignoring the Number of the Object Name in Contents


Storii Darkheart
 Share

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

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

Recommended Posts

Hello!

 

This answer may be on the forums but I couldn't find it in search.

I'm trying to make it so that my script 'ignores' the added number to an object when multiple of the same named object are placed in the contents.

My script takes a specifically named object thats placed into its contents and spits out to the user a different item if the name matches. But when a duplicate item is added (ex the contents of the box now has Item and Item 1 if a second is accidentally added) the script will only interact with the first instance because it directly matches the name of the object. 

 

Is there a way to make it so that the script disregards the added number? The name of the item it looks for is contained in a list if that makes a difference.

 

Any assistance would be greatly appreciated. 

 

Thanks!

Link to comment
Share on other sites

I don't understand the question yet.

You have a container with Item A and Item B in it. And then ...

11 minutes ago, Storii Darkheart said:

My script takes a specifically named object thats placed into its contents and spits out to the user a different item if the name matches.

Someone adds another copy of Item A to the container and the script gives that person Item B?  So now the container has Item A, Item A 1, and Item B.  

And now what happens?  Or, rather, what do you want to happen?

Link to comment
Share on other sites

Sorry I guess it’s a little confusing. 
 

The container has Item A in its contents. When someone puts in Item B then touches it, it gives that person Item A and then removes Item B from the contents. 
 

The issue is when someone puts in multiple Item B causing the container to now have Item B and Item B 1 but the script doesn’t recognize Item B 1 and doesn’t receive 2 of Item A because it doesn’t match up. 
 

Essentially I’m asking if there’s a way for it to recognize that Item B 1 is the same as Item B and treat it as such even tho it’s not contained in my list 

Link to comment
Share on other sites

41 minutes ago, Storii Darkheart said:

The issue is when someone puts in multiple Item B causing the container to now have Item B and Item B 1 but the script doesn’t recognize Item B 1 and doesn’t receive 2 of Item A because it doesn’t match up. 

Still confusing.  If the container has Item B and Item B 1, I don't understand how it can ever give Item A, which isn't even in the container.

 

I suppose it doesn't matter whether I understand what the script is doing. You just want to know how to tell the script that Item B and Item B 1 are to be considered the same, right? So, if you know that the valid choice is "anything with a name that includes Item B", just tell your script

changed (integer change)
{
     integer New_total = llGetInventoryNumber(INVENTORY_OBJECT);
     if ( New_total  > iPrevious_total )
     {
          integer AllA;
          integer AllB;
          integer i;
          while ( i < New_total )
          {
               string name = llGetInventoryName(INVENTORY_OBJECT,i);
               if ( ~llSubStringIndex(name, "Item A") )
               {
                     ++AllA;
               }
               else if ( ~llSubStringIndex(name, "Item B") )
               {
                     ++AllB;
               }
               ++i;
          }
          if ( AllA > AllB )
          {
               llGiveInventory( This_av, "Item B" );
               llRemoveInventory("Item A 1");
          }
          else 
          if ( AllB > AllA )
          {
               llGiveInventory( This_av, "Item A" );
               llRemoveInventory("Item B 1");
          }
     }
     iPrevious_total = New_total;
}

I think that will do it.   Typed quickly, so there may be a typo in there somewhere.               

Edited by Rolig Loon
Dang. I am typing too fast.
Link to comment
Share on other sites

50 minutes ago, Storii Darkheart said:

Sorry I guess it’s a little confusing. 

...

If I understood it correctly, then I would say that for this problem the best solution would be to use a simple regular expression. But since there is no direct support for regex in LSL in my opinion (only indirect), then you probably have to implement some simple parsing of the content item's name.

I would do it this way:

1) match the item name with names on your list, but match only the beginning of the name (or prefix), e.g. if on your list there is "SomeItem" and the item that was put in object is "SomeItem 1", then match just the beginning/common part of the string. Or in other words, check if that pasted item's name starts with the name on the list.

2) If the beginning/common part matches, then continue matching whitespace and integer numbers (probably character by character).

3) If that still matched, then you have a match and you can continue doing what you wanted to do (e.g. give some item in return).

There are probably more ways to achieve the same. You could for example split the item's name and ignore the last number part.

 

Edit: Maybe it would be more simple to do it by splitting the string as I said in last paragraph.

Edited by tomm55
Link to comment
Share on other sites

One error at the end.   The last line should be iPrevious_total  = llGetInventoryNumber(INVENTORY_OBJECT);  because you want to start the next time around by comparing the new total with whatever you ended up with this time.  Ideally, iPrevious_total shouldn't change at all from one try to the next.

Link to comment
Share on other sites

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