Converting string to boolean

Hi guys,

I have a few doors and few keys to open specific doors. what I am trying to do is to create a function so that i can reuse them.

The problem that i encounter is converting a series of string to boolean. Can't use parseBoolean(); Don't even know that it is the correct way to do it or is there a better way? Please assist and thanks in advance!

var doorNum: int;
static var accessGranted_1: boolean;
var isOpen_1: boolean = false;

checkTileOpenDoor_spaceship(1);

function checkTileOpenDoor_spaceship(doorNum){

    var doorIndex: int = doorNum;       
    var currentTileTypeIndex: String = "TileOpenDoor_" + doorIndex;
    var isOpenIndex: boolean = parseBoolean("isOpen_" + doorIndex);
    var accessGrantedIndex: boolean = parseBoolean("accessGranted_" + doorIndex);
    var TileEndIndex: String = "TileEnd_" + doorIndex;

    if (currentTileType == currentTileTypeIndex && !isOpenIndex && accessGranted){
        //open door

        GameObject.Find(TileEndIndex).animation.wrapMode = WrapMode.Once;
        GameObject.Find(TileEndIndex).animation.Play("open");
        isOpenIndex = true;

    } else if (currentTileType != currentTileTypeIndex && isOpenIndex){
        //close door

        GameObject.Find(TileEndIndex).animation.wrapMode = WrapMode.Once;
        GameObject.Find(TileEndIndex).animation.Play("close");
        isOpenIndex = false;

    }
}

Rdgs, James Ser

you should use bool.Parse to convert a string to it's logical boolean representation.

You can create a hashtable and store the values in it then read it from there if you absolutely need to reference them this way. Easier would be to use boolean arrays.

public var doorNum: int;
static var accessGranted: boolean[];
public var isOpen: boolean[];

function checkTileOpenDoor_spaceship( door: int ){

  var currentTileTypeIndex: String = "TileOpenDoor_" + door;
  var TileEndIndex: String = "TileEnd_" + door;

  if (currentTileType == currentTileTypeIndex && !isOpen[ door ] && accessGranted [ door ]){
    //open door

    GameObject.Find(TileEndIndex).animation.wrapMode = WrapMode.Once;
    GameObject.Find(TileEndIndex).animation.Play("open");
    isOpen[ door ] = true;

  } else if (currentTileType != currentTileTypeIndex && isOpen[ door ]){
    //close door

    GameObject.Find(TileEndIndex).animation.wrapMode = WrapMode.Once;
    GameObject.Find(TileEndIndex).animation.Play("close");
    isOpen[ door ] = false;

  }
}