- Home /
Converting a String to Another Object's Boolean
I'm trying to make a system working so that I can enable/disable "Flags" and colliders will turn on/off depending on whether their flag is currently active. This is so I can block off certain portions of the story until they meet a specific requirement.
The problem I'm having is getting a collider to check if it's flag has been activated/de-activated. I need it to be a string I can type in because I intend on having many flags and colliders which will use this, so I need to be able to type in which flag I need to be checked in the inspector, and have the script take it from there.
The example is: I assign the below script to a collider and I type in which Flag it needs to check in order for it to disable. I enable the triggers so the object can become walk-throughable, but currently, if I press "l" nothing happens at all.
var FlagNeeded = "";
function Update () {
if(FlagControl.FlagNeeded == true){
collider.isTrigger = true;
}
if(Input.GetKeyUp("l")){
FlagControl.Flag01 = true;
}
}
And this goes on the FlagControl, which handles all of the flags.
static var Flag01 : boolean = false;
So what is the FlagNeeded
here supposed to do? Write it in pseudocode, don't worry that it doesn't work.
FlagNeeded is the string I manually type in, and what I'm trying to do is get the script to see if a boolean with the same name of "FlagNeeded" is enabled in the FlagControl script and if it is to turn on the collider's trigger.
Answer by DaveA · Sep 07, 2011 at 01:25 AM
I think you want a Hashtable. Use the flag name as the key and the value would be the boolean. Have one such thing (singleton or just one instance of a 'flag manager' type of script.
Would you $$anonymous$$d giving an example? I'm completely new to Hashtables.