Jump to content

Script that counts and sorts objects by name into lists


Starax Sands
 Share

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

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

Recommended Posts

I'm trying to get this section to work but it appears I just don't know what I'm doing wrong. I'm trying to use llGetInventoryName() to count the number of objects in the inventory with specific names (three different names) and then add them to their respective lists depending on their name. But it just doesn't seem to be working at all. The problem seems to be when it's trying to get the name of the object because it's just returning an empty string and going straight to the "not a valid object" if statement even if it does have the appropriate name. Any advice or instruction is greatly appreciated!

Link to comment
Share on other sites

Due to the last if check when I drop an object, even with the right name, in the prim, I get a script error saying "Unable to give inventory: 'No item named ''.'." which is what leads me to believe it's just returning an empty string and I don't really know why. 

Link to comment
Share on other sites

If that's your end goal, you really don't need to go to all that trouble. After all, when you go to give one of the items it will either be in inventory or it won't. All you really need to do at the time of the request is run a little test to verify that the requested item is there.

if ( llGetInventoryType(name_of_requested_object) != -1) {//go ahead and give the object }

As it is, your changed event will respond to any addition or subtraction to inventory. Also, thanks to the fact that you have used "if" rather than "if else" throughout the script, most of the tests will usually return FALSE. If I were you, I would eliminate the event altogether and simply test as I indicated above.

Link to comment
Share on other sites

What Rolig said.

The Reason your script fails is:

You get the number of inventory objets in "count" - lets say it's 5

You try to get the name of the 5th object then and that fails.

If you have 5 objects in your inventory they will have the numbers: 0,1,2,3,4 there is no #5

Nearly all things in LSL start counting with 0.

 

Link to comment
Share on other sites

Part of the problem is that you can't have identically named objects in a prim's inventory.   When you drop in several copies of the same item, SL renames it for you. so you end up with something like "First Object", "First Object 1", "First Object 2", and so on.   So you only have one copy of "First Object" to give out.

So when you're building your lists, I think you need something like this: 

list glFirstObjects;list glSecondObjects;list glThirdObjects;string gsFirstObjectName ="First Object";string gsSecondObjectName = "Second Object";string gsThirdObjectName ="Third Object";default{	changed(integer change)	{		if(change & CHANGED_INVENTORY){			integer max = llGetInventoryNumber(INVENTORY_OBJECT);			integer counter;			do {				string str = llGetInventoryName(INVENTORY_OBJECT, counter);				if(~llSubStringIndex(str, gsFirstObjectName)){					//if it's called "First Object some number"					if(!~llListFindList(glFirstObjects, [str])){						//and it's not already in my list						glFirstObjects+=[str];						//add it					}				}				else if (~llSubStringIndex(str,gsSecondObjectName)){					if(!~llListFindList(glSecondObjects, [str])){						glSecondObjects+=[str];					}				}				else if (~llSubStringIndex(str,gsThirdObjectName)){					if(!~llListFindList(glThirdObjects, [str])){						glThirdObjects+=[str]; 					}				}			}			while (++counter<max);		}	}}

Then, when someone chooses an item, offer them a choice of  "First Object", "Second Object" and  "Third Object" and handle their reply something like this:

	listen(integer channel, string name, key id, string message)	{		if(gsFirstObjectName == message){			if(glFirstObjects !=[]){				//give the first item on the list				llGiveInventory(id, llList2String(glFirstObjects,0));				//and remove it from the list				glFirstObjects=llDeleteSubList(glFirstObjects, 0, 0);			}			else{				llRegionSayTo(id,0, "Sorry, but I'm out of stock of "+gsFirstObjectName+"s right now.")			}		}		// and so on	}

I've not tested this code, but I think it should work.

Link to comment
Share on other sites

The reason I'm using the changed event is so that the hover text can keep track of how many of each object is in the inventory, and update when more is added. And also so that it can send a message to the owner if it's running low. The objects inside are going to be no copy so there will be multiples of each and will dwindle as the object is used.

Correct me if I'm wrong, but I think using the changed event is the easiest way to create this functionality.

Link to comment
Share on other sites

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