Jump to content

Counting characters in names of inventory items


Emma Krokus
 Share

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

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

Recommended Posts

Coming up against this pesky 12 character item limit for buttons - why oh why does it not tell you which is the one that's too long?

So, I am wondering if anyone may have written a little script to do just that?

I've googled without much success so far - quite possibly because I am not sure of the right search terms. Any help would be much appreciated!

Thank you !

Emma :) 

 

 

Link to comment
Share on other sites

default
{
    touch_start(integer total_number)
    {
        integer count = llGetInventoryNumber(INVENTORY_OBJECT);
        integer item;

        while (item < count)
        {
            string name = llGetInventoryName(INVENTORY_OBJECT, item);
            integer length = llStringLength(name);

            if (length > 12)
            {
                llOwnerSay("\"" + name + "\" is too long.");
            }
            ++item;
        }
    }
}

841209be29.png

[06:21:06] Inventory: "This name is probably too long and shouldn't exist" is too long.

Thankfully it doesn't seem possible to put multi-byte characters into object names, so you don't have to handle weird characters (which could be done with llEscapeURL).

Edited by Wulfie Reanimator
  • Thanks 1
Link to comment
Share on other sites

Thank you Wulfie - that's worked a treat. I tweaked it by changing the inventory type to INVENTORY_SOUNDS to suit my particular need :).

It's hugely helpful to me - and I hope others who come across this little gem too.

Now I gotta work out why my script is telling me I still have too long a string in it... :( (and no, no funny characters in those names)

/me pulls at remaining hairs.

Emma :) 

Link to comment
Share on other sites

  • 5 weeks later...

There are two other options you could consider:

 

1. Creating two lists: one with full names (for giving) and one for the buttons (truncated) - e.g.:

list glInventory;
list glButtons;

CreateLists()
{
  	glInventory = [];
  	glButtons = [];
  
	integer i;
	integer iInventoryCount = llGetInventoryNumber(INVENTORY_ALL);
	if (iInventoryCount == 1) //Only this script present
	{
		return;
	}

	for (i = 0; i < iInventoryCount; ++i)
	{
      		string sName = llGetInventoryName(INVENTORY_ALL, i);
    		glInventory += sName;
    		glButtons += llGetSubString(sName, 0, 11);      
	}
  
  	i = llListFindList(glInventory, [llGetScriptName()]); //Remove this script from the lists
  	if (~i)
    	{
      		glInventory = llDeleteSubList(glInventory, i, i);
      		glButtons = llDeleteSubList(glButtons, i, i);
    	}
}

GiveInventoryItem(key pkId, string psMessage) //Where pkId is the recipient key and psMessage is the selected button from the listen() event
{
  	integer iIndex = llListFindList(glButtons, psMessage);
  	if (~iIndex)
    	{
      		llGiveInventory(pkId, llList2String(glInventory, iIndex));
    	}
}

Sorry for any code indentation flukes... the code window is....iffy. Obviously, you'd need to use glButtons in the menu as the button list. I did not put that into this snippet.

 

2. Using a not dissimilar idea as above, but using numbers for the buttons and using the menu text to display a legend. It's a bit more complex, but usually  more descriptive.

Edited by Bugs Larnia
Changed function name and added comment line in script snippet
Link to comment
Share on other sites

On 6/12/2020 at 4:06 PM, Emma Krokus said:

Thank you Wulfie - that's worked a treat. I tweaked it by changing the inventory type to INVENTORY_SOUNDS to suit my particular need :).

It's hugely helpful to me - and I hope others who come across this little gem too.

Now I gotta work out why my script is telling me I still have too long a string in it... :( (and no, no funny characters in those names)

/me pulls at remaining hairs.

Emma :) 

Are you sure it's complaining about string length and not the number of buttons (which also has a max of 12)?

  • Like 1
Link to comment
Share on other sites

Although this is an oldish topic, I'll just mention that the byte length limit for dialog button labels is 24, and as these are derived, in this case, from inventory item names, there shouldn't be any multi-byte characters to contend with. 12 characters is a rough average of how many characters will be visible on the button itself: on my system a label consisting of 24 "i"s appears in full, but one consisting of 24 "w"s shows only nine of them. Note that the full label string, including the unseen characters, will be sent to chat when the button is clicked.

  • Like 2
Link to comment
Share on other sites

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