Key in inventory problem

I’m making a text based adventure game. I have a working inventory (var inventory: string :wink: but I’m trying to make it so that if you try to open a locked door while the key is in your inventory it opens, but for some reason my if statement here > ( if (Inventory.Element0 == [“IronKey”]) ) is never true, and I would like to know why

Jake :slight_smile:

At first sight, you’re placing the square brackets in the wrong place:

if (Inventory.Element[0] == "IronKey"){

If this doesn’t work, edit your question and post the script you’re using.

var text : GUIText;
var answer : String;
enum Things {Chest, Door, Room, Cloak, CD, IronKey, Not}
var focusedOn : Things;
var Inventory:String;

function Update () {
text.text = answer;
if (Input.GetButtonDown(“Return”)) {
answer = “I don’t understand that”;
}
}
function chest () {
answer = “It’s a basic wooden chest, not locked, nothing special”;
focusedOn = Things.Chest;
}
function door () {
answer = “Nothing special, just a door”;
focusedOn = Things.Door;
}
function open () {
if (focusedOn == Things.Chest) {
answer = “There is an iron key, a cloak, and a CD”;
Inventory += [“IronKey”];
Inventory += [“Cloak”];
Inventory += [“CD”];
}
if (focusedOn == Things.Door) {
if (Inventory.Element[0] == “IronKey”) {
answer = “The door opened with the iron key”;
}
else {
answer = “Locked”;
}
}
}

the error says
“MissingFieldException: Field ‘System.String.Element’ not found.
Boo.Lang.Runtime.DynamicDispatching.SliceDispatcherFactory.ResolveMember ()”