How To Remove Item From List

Hi there,
I am hoping someone can help me find the answer to this.

I have a list, wtih so many items. I want to remove items from it, but am continually getting an error that “Method
not found”

This is my code.

///java
myList.remove(item[index]);

///i have also tried.
myList.remove(0);

Any help would be greatly appreciated.

Does your class/file has the name myList ? Are you using the right Namespace (System.Collections.Generic)? Dont know, but the syntax looks right to me. Maybe post all your code

I am not importing anything. It is a simple JS script.

The function and method are being reached. Do I need to #import a certain type? Funny thing is that I can add() to list.

function createSpline()
{
	splinePoints.Add(Camera.main.WorldToScreenPoint(splineNodePos));
}


function removeNode()
{
	splineLine.remove(someIndex);
}

well in c# you need to do it. In US I dont know to be honest. Try it out and import System.Collections.Generic. I have no glue about UnityScript ^^

I just noticed I was calling the wrong object. However I corrected it, and still get the same error.

function createSpline()
{
	splinePoints.Add(Camera.main.WorldToScreenPoint(splineNodePos));
	//makeSpline
	splineLine.MakeSpline(splinePoints.ToArray());
	removeNodes();	//for testing
}	

function removeNodes()
{	
	yield WaitForSeconds(2.0);
	splinePoints.remove(1);
	yield WaitForSeconds(1.0);
	splinePoints.remove(2);
	
	
}

Yes, I just tried the import System.Collections.Generic;, but get the same result.

:?#Confused.

How is splinePoints declared?

Sorry for not posting the whole script but it is kind of sloppy right now.

private var splinePoints = new List.<Vector2>();

edit:
splineLine is a VectorLine(), a class of the Asset Vectrosity. It makes up the spline. splinePoints, is a list of Vector2, which makes up the array passed into the spline, making up the spline.

var splineLine : VectorLine;
private var splinePoints = new List.<Vector2>();


function Start()
{
	splineLine = VectorLine("Spline", new Vector2[segments], splineMaterial, 2.0, LineType.Continuous);
}

function createSpline()
{
	///this method is called on a timer when mouse is down

	///add a position, vector to the list splinePoints
	splinePoints.Add(Camera.main.WorldToScreenPoint(splineNodePos));
	

	//makeSpline
	splineLine.MakeSpline(splinePoints.ToArray());
}

A search of MSDN would have sufficed.

List.Remove() http://msdn.microsoft.com/en-us/library/cd666k3e(v=vs.90).aspx
List.RemoveAt() http://msdn.microsoft.com/en-us/library/5cw9x18z(v=vs.90).aspx

Note the capital R

I tried a cap but again it is not working. I get the error…

In theory, am I calling this correctly?

someList.Remove(index);
///or...
someList.remove(someIndex);

The correct answer is

myList.RemoveAt(index);
1 Like

Was just about to post this. Yes RemoveAt is the correct way to do this.