Jump to content

Delete Item in List


EnCore Mayne
 Share

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

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

Recommended Posts

newbie here.

i'm running a script on a prim that lists all of the objects of its contents

contents_total = llGetInventoryNumber(INVENTORY_OBJECT);
for (counter = 0; counter <= contents_total; ++counter)
{
	contents_name = llGetInventoryName(INVENTORY_OBJECT, counter);//strings
	objectlist += contents_name;//list of object names
}

all well and good so far but i want to check all the listed items for a specific string. if it contains that string of characters somewhere within the item's name (eg. "Freya", or "freya") i'd like to delete that item from the list. possible?

Link to comment
Share on other sites

50 minutes ago, KT Kingsley said:

Maybe just not add it to the list if it meets the criteria:

if (llSubStringIndex (llToLower (contents_name), "freya") == -1) objectlist += contents_name;//list of object names

!GENIUS!
works like a charm.

  • Like 1
Link to comment
Share on other sites

22 hours ago, EnCore Mayne said:

 

This is wrong. Using this function llToLower defeats the literal match.

 if (llSubStringIndex (llToLower (contents_name), "freya") == -1)

 It will just add a lower case converted entry.

 objectlist += contents_name;//list of object names

Edited by steph Arnott
Link to comment
Share on other sites

10 hours ago, steph Arnott said:

This is wrong. Using this function llToLower defeats the literal match.

 if (llSubStringIndex (llToLower (contents_name), "freya") == -1)

 It will just add a lower case converted entry. 

KT's suggested code is fine, I think you've misunderstood what it's doing.

The actual variable contents_name is not being updated or assigned anything new. The to lower conversion only exists within the scope of the conditional test. The whole point is to see if substringindex is able to locate "freya". Since the match needs to be case insensitive, we can make the test easier by converting a copy of the string to lower and checking for that. If substringindex fails to locate the substringstring, then the function returns -1. So if -1 == -1, then we know that the variable contents_name did not contain an instance of "freya" (or "Freya" or "FREYA" etc etc) and is therefore safe to add to the list.

  • Like 1
Link to comment
Share on other sites

2 minutes ago, Fenix Eldritch said:

KT's suggested code is fine, I think you've misunderstood what it's doing.

The actual variable contents_name is not being updated or assigned anything new. The to lower conversion only exists within the scope of the conditional test. The whole point is to see if substringindex is able to locate "freya". Since the match needs to be case insensitive, we can make the test easier by converting a copy of the string to lower and checking for that. If substringindex fails to locate the substringstring, then the function returns -1. So if -1 == -1, then we know that the variable contents_name did not contain an instance of "freya" (or "Freya" or "FREYA" etc etc) and is therefore safe to add to the list.

That is not doing what was asked. ' item's name (eg. "Freya", or "freya") i'd like to delete that item from the list. possible? '

        integer index = llListFindList(temp, ["freya"];
        temp = llDeleteSubList(temp, index, index); 

 

Link to comment
Share on other sites

You know as well as I do that there are multiple ways to achieve that goal. KT offered an alternative method that prevents adding the problematic string in the first place. It is equally as valid as removing the list entry after the fact. Neither approaches are "wrong" as you claimed. Furthermore, your assessment that KT's code would "just add a lower case converted entry" to the list is flat out false and suggested to me you didn't understand what it was intending to do.

But I already can see where this conversation is headed, so I'll bow out now since the OP has their answer.

  • Like 3
Link to comment
Share on other sites

52 minutes ago, Fenix Eldritch said:
11 hours ago, steph Arnott said:

This is wrong. Using this function llToLower defeats the literal match.

 if (llSubStringIndex (llToLower (contents_name), "freya") == -1)

 It will just add a lower case converted entry. 

 KT's suggested code is fine, I think you've misunderstood what it's doing.

“IF” statements are.....hard.

Link to comment
Share on other sites

2 minutes ago, Fenix Eldritch said:

You know as well as I do that there are multiple ways to achieve that goal. KT offered an alternative method that prevents adding the problematic string in the first place. It is equally as valid as removing the list entry after the fact. Neither approaches are "wrong" as you claimed. Furthermore, your assessment that KT's code would "just add a lower case converted entry" to the list is flat out false and suggested to me you didn't understand what it was intending to do.

But I already can see where this conversation is headed, so I'll bow out now since the OP has their answer.

The first way will take forever. That function should be avoided at all costs and used only when absolutely neccessary.  If you want to take 30 seconds as opposed to 1 second then  carry on.

Link to comment
Share on other sites

3 hours ago, Love Zhaoying said:

“IF” statements are.....hard.

Only if you use arrant nonsense like this.

if (llSubStringIndex (llToLower (contents_name), "freya" ) == -1)

There is no way that would even compile on the main grid. And i doubt it would even on the OS grid.

Edited by steph Arnott
Link to comment
Share on other sites

33 minutes ago, steph Arnott said:

Only if you use arrant nonsense like this.

if (llSubStringIndex (llToLower (contents_name), "freya" ) == -1)

There is no way that would even compile on the main grid. And i doubt it would even on the OS grid.

Used in complete form (as in the whole additional line KT posted)  it compiles and runs fine. Unless I am on some other main grid.

Link to comment
Share on other sites

2 hours ago, mikka Luik said:

 

This is what you are doing. The data input is not a list at all. The data string is added to a list which is not what your OP was on about. The issue with this is that it can add multiple entries to the list as it converts to lower case.  It will also convert the first encounter. The one you do not want.

string contents_name = "Freya";
integer null = -1;
default 
{
	state_entry()
	{
	}
	touch_start(integer total_number)
	{
		if (llSubStringIndex (llToLower (contents_name), "freya") == null)
		{
			//objectlist += contents_name;
		}
	}
}

 

Edited by steph Arnott
Link to comment
Share on other sites

@steph Arnott really do not know what you are 'on about' with your comments like

1 hour ago, steph Arnott said:

Be odd seeing as you can not convert list to string with that.

and

16 hours ago, steph Arnott said:

This is wrong. Using this function llToLower defeats the literal match. 

and

16 hours ago, steph Arnott said:

 It will just add a lower case converted entry.

The OP had code that was going through the inventory, getting names, and adding to a list. Whilst they referred to 'deleting from the list, the suggestion given does that by never adding to the list. There was no 'literal' match asked for by the OP, and no lower case converted entery gets added, .. oh and yes it would compile:

        integer counter;
        list objectlist = [];
        
        integer contents_total = llGetInventoryNumber(INVENTORY_OBJECT);
        for (counter = 0; counter <= contents_total; ++counter)
        {
            string contents_name = llGetInventoryName(INVENTORY_OBJECT, counter);//strings
            if (llSubStringIndex (llToLower (contents_name), "freya") == -1) objectlist += contents_name;//list of object names
        }

The above (with declarations added) compiles perfectly and only adds to the list, Inventory Objects that do not have the 'string of characters' freya (OP's request) to the list.

  • Thanks 1
Link to comment
Share on other sites

3 minutes ago, Wandering Soulstar said:

@steph Arnott really do not know what you are 'on about' with your comments like

and

and

The OP had code that was going through the inventory, getting names, and adding to a list. Whilst they referred to 'deleting from the list, the suggestion given does that by never adding to the list. There was no 'literal' match asked for by the OP, and no lower case converted entery gets added, .. oh and yes it would compile:


        integer counter;
        list objectlist = [];
        
        integer contents_total = llGetInventoryNumber(INVENTORY_OBJECT);
        for (counter = 0; counter <= contents_total; ++counter)
        {
            string contents_name = llGetInventoryName(INVENTORY_OBJECT, counter);//strings
            if (llSubStringIndex (llToLower (contents_name), "freya") == -1) objectlist += contents_name;//list of object names
        }

The above (with declarations added) compiles perfectly and only adds to the list, Inventory Objects that do not have the 'string of characters' freya (OP's request) to the list.

' i'd like to delete that item from the list. possible? ' 'llGetInventoryName' > ' Returns a string '.

Edited by steph Arnott
Link to comment
Share on other sites

choosing to defer from the controversy (even tho i do love a good debate) i'd just like to reiterate that i thought KT's solution to my request was bang on and i indicated so in my reply. in other words, hallelujah, it works!

now, i do admit, there are many ways to skin a cat, points can be taken from both sides; however, KT's intuitive grasp of the problem, using only the language and logic of my original post came up with not only the solution i was asking for, but an additional resolution i was eventually going to run into once i plugged in his code.

searching for all instances of a string (Freya, freya, FreYa, etc.) seems to be managed astoundingly well by checking the converted lowercase inventory names against the lowercase instance of the string. once again, an intuitive solution to the problem my tiny brain was going to eventually have to reckon with all served in two lines of code.

GENIUS! or Villain?

Only God Knows ....

 

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

5 hours ago, steph Arnott said:

It will work if the string is evalutaed before being listed. But that was not your post. You can not use that code if it is already in a list.

nothing personal but i've never had a single post reply that you've ever made be helpful to me at all. please don't be offended if i disregard your input. i'm sure you make sense, just not to my level. cheers.

  • Thanks 1
Link to comment
Share on other sites

Wooky hooky crystal ball. Reveal LSL-to-steph once and for all. On a moonlight night such as this, watch Steph strip naked and start to script. Rubs her hands and cackles with glee...what scripting woo can I peddle to thee. The forum watched in utter despair as Steph threw her hands up into the air. "ANCIENT GODS I DO CALL THEE, SCRIPTING WOO, BRING TO ME". The heavens did open and the light did shine, scripting woo flew-down-from-the-sky. She gathered it up, shouted "HEE HEE HEE, SCRIPTING WOO FOR ALL-TO-SEE". She leapt to the forum, to post her best. And as-per-usual was met with jest. Hard did she try, to convince thee, but you are not stupid, unlike she. And with that note, hadto did flee, awaiting the strike Steph will fling at me. But it was worth it, to watch her squirm I will leave after shouting.."VIVA LA BURN!"

 

  • Haha 3
Link to comment
Share on other sites

integer contents_total = llGetInventoryNumber(INVENTORY_OBJECT);
integer counter = 0;
for (counter; counter < contents_total; ++counter) {
	string contents_name = llGetInventoryName(INVENTORY_OBJECT, counter);
    if (llSubStringIndex(llToLower(contents_name), "freya") == -1) {
		objectlist += [contents_name];
    }
}

theres how it should be since i think steph was being picky with variable types.

Link to comment
Share on other sites

14 minutes ago, VenKellie said:

integer contents_total = llGetInventoryNumber(INVENTORY_OBJECT);
integer counter = 0;
for (counter; counter < contents_total; ++counter) {
	string contents_name = llGetInventoryName(INVENTORY_OBJECT, counter);
    if (llSubStringIndex(llToLower(contents_name), "freya") == -1) {
		objectlist += [contents_name];
    }
}

theres how it should be since i think steph was being picky with variable types.

Not about being 'picky'. Was about strings and lists.  Two entirely different things. Also i could have used ~ rather than == -1 and  returned either zero or non-zero.

Edited by steph Arnott
Link to comment
Share on other sites

1 hour ago, steph Arnott said:

Not about being 'picky'. Was about strings and lists.  Two entirely different things. Also i could have used ~ rather than == -1 and  returned either zero or non-zero.

da fudge? strings, vectors and integers can all go into a list, thats what a list is for

Link to comment
Share on other sites

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