Help removing a Custom Class from a List in UnityScript

Hey folks! I have been Goggling my head off today trying to find out how to remove an item from a list of custom classes (involving UnityScript which is my preferred language of choice). I managed to figure out how to add to the list but removing from that list seems to be an entirely different beast. I think I may need to add another constructor to my custom class but not sure exactly.

The error I am getting with the code below:
“Assets/Scripts/BuffInterface.js(21,56): BCE0023: No appropriate version of ‘System.Collections.Generic.List.IndexOf(BuffClass)’ for the argument list ‘(String)’ was found.”


#pragma strict

public class BuffClass {
	public var name : String;
	public var icon : Texture2D;
	public var description : String;

	public function BuffClass(newName : String, newIcon : Texture2D, newDescription : String){
		name = newName;
		icon = newIcon;
		description = newDescription;


#pragma strict
import System.Collections.Generic;
public var debuffIcon1 : Texture2D;
public var debuffIcon2 : Texture2D;
private var buffs : List.<BuffClass> = new List.<BuffClass>();

function Start () {
	buffs.Add( new BuffClass("Poison",debuffIcon1,"Oh noes!"));
	buffs.Add( new BuffClass("Radiation", debuffIcon2,"Ouch!"));

public function ApplyBuff(name : String, icon : Texture2D, description : String, invoke : String){
	buffs.Add( new BuffClass(name,icon,description));
	Invoke (invoke,.1f);

public function RemoveBuff(name : String){
	for(item in buffs){ //NOTE: Thought going through a loop might allow me further access into the class.
		if( == name){
			var indexOfBuff = buffs.IndexOf(; //NOTE: I am ultimately trying to remove something from the list by its inner class variable name (i.e. via RemoveBuff("Poison") or RemoveBuff("Radiation").)
	//var buffToRemove = buffs.IndexOf(BuffClass(name,icon,description));

Thanks for any and all help!

The IndexOf function wants a reference to the object as an argument.
You’ll get the correct index with this:

var indexOfBuff = buffs.IndexOf(item);

But you’re making it more difficult than you have to. If I understood you correctly, you can squeeze the function into this:

for (var i = buffs.length - 1; i >= 0; i--) { // reverse iteration
    if (buffs*.name == name) {*

That’s how I’d do it.
BTW, you can’t modify a collection (list, array…) inside a foreach loop ( for (x in y) syntax).
If there are multiple buffs with the same name, the code above only removes the first match. To remove them all, just delete the breakstatement from the loop body.
(This is why the code iterates over the list in reverse – you can remove items without having to worry about jumping over any by accident.)