Jump to content

Lists - Replace Value in empty list ["","",""] and also check to see if value exists in list.


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

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

Recommended Posts

Posted (edited)

I know all about arrays in C#/PowerShell, but this list thing is killing me.

I just want to create an empty list ["","",""] then add/replace values to specific locations in the list.
i.e. List[3] = "value";

Then I also want to check the list to see if a value exists anywhere in the list.
i.e. List.Contains("value");

Any help would be greatly appreciated!

Edited by Pepper Dakota
Edit
Posted

When I use llListReplaceList(NamesList, [message], 1, 1);  and then llListFindList(NamesList, [llDetectedName(0)]) I get -1, indicating the value doesn't exist.
Message is llDetectedName(0) passed from another script.

Posted

LSL lists are zero-based, and negative indices count from the end instead.

LSL lists are also immutable: if you use llListReplaceList, you must assign the result somewhere, the original list is untouched.

E.g.

namesList = llListReplaceList(namesList, [message], 1, 1);

Posted (edited)

list lMyList = ["A","B","C"];

if (!llListFindList( lMyList,["A"]) ) { llSay(0,"A is in lMyLst");}

lMyList = llListReplaceList(lMyList, ["D"],1,1);

llSay(0, llDumpList2String( lMyList, ", "));   // Yields  "A","D","C"

Edited by Rolig Loon
typos. as always.
Posted (edited)

I use 

llListReplaceList(NamesList, [message], 1, 1);

But when I then use

llListFindList(NamesList,[message]))

I get -1, so I assume the value never made it to the list.

Edited by Pepper Dakota
Posted (edited)
12 minutes ago, Pepper Dakota said:

When I use llListReplaceList(NamesList, [message], 1, 1);  and then llListFindList(NamesList, [llDetectedName(0)]) I get -1, indicating the value doesn't exist.

The llDetected* functions only yield results in events that can actually detect something ( touch, touch_start, touch_end, sensor, ..).  If you want to pass a value of some variable loaded by llDetectedName(0) in another event, you'll have to assign it to a global variable to do the job.

touch_start(integer num)
{
    strName = llDetectedName(0);   /// Where strName has previously been defined as a global string variable
}

Then you can pass strName anywhere you like and it will contain the value you loaded in that touch_start event

 

     

Edited by Rolig Loon
Posted

I think I get the llListFindList thing, the logic checks out, but 

list lMyList = ["A","B","C"];
lMyList = llListReplaceList(lMyList, ["D"],1,1);

What is the 1, 1 representing?

Posted
2 minutes ago, Rolig Loon said:

The llDetected* functions only yield results in events that can actually detect something ( touch, touch_start, touch_end, sensor, ..).  If you want to pass a value of some variable loaded by llDetectedName(0) in another event, you'll have to assign it to a global variable to do the job.

This is already being passed by another script, llDetectedName(0) is passed via llMessageLinked as "message"

 

Posted (edited)

Here's what I have;

llListReplaceList(NamesList, [message], 0, 0);
llSay(0, "List entry 1 updated: " + message);            
if(!llListFindList(NamesList, [message])){
    llSay(0, message + " is in NamesList");
}else{
    llSay(0, message + " was not found in the list.");     
}

Here's the output:
List entry 1 updated: Pepper Dakota
Pepper Dakota was not found in the list.

string message is llDetectedName(0) passed by another script.

list NamesList   = []; - but even tried list NamesList = ["","",""]

Edited by Pepper Dakota
Posted
4 minutes ago, Pepper Dakota said:

and it worked

Ah... oops.  As you could tell from the fact that I edited a couple of my posts, I have a tendency to generate typos when I type quickly as I write a forum post.  I missed that one.  Sorry.

  • Like 1
Posted (edited)

I just used this and it seems to have added the name to the list successfully.

NamesList = [message] + NamesList;

I think 
llListFindList(NamesList, [llDetectedName(0)]) versus !llListFindList(NamesList, [llDetectedName(0)]) is a bit counter intuitive,
but I am getting what I need now
Thanks everyone!

 

Edited by Pepper Dakota
  • Like 1
Posted
1 hour ago, Pepper Dakota said:

Here's what I have;

llListReplaceList(NamesList, [message], 0, 0);
llSay(0, "List entry 1 updated: " + message);            
if(!llListFindList(NamesList, [message])){
    llSay(0, message + " is in NamesList");
}else{
    llSay(0, message + " was not found in the list.");     
}

Here's the output:
List entry 1 updated: Pepper Dakota
Pepper Dakota was not found in the list.

string message is llDetectedName(0) passed by another script.

list NamesList   = []; - but even tried list NamesList = ["","",""]

Re-read this 

1 hour ago, Frionil Fang said:

lists are also immutable: if you use llListReplaceList, you must assign the result somewhere, the original list is untouched.

E.g.

namesList = llListReplaceList(namesList, [message], 1, 1);

not 

llListReplaceList(NamesList, [message], 0, 0);

but

NamesList = llListReplaceList(NamesList, [message], 0, 0);

 

You are about to reply to a thread that has been inactive for 140 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
×
×
  • Create New...