- Home /
Array of Strings and keyword "in"
I understand that a way to use the keyword in would be:
var names = Array("max", "rick", "joe");
if ("joe" in names) Debug.Log("Found Joe!");
I created a variable which is an Array of possible tags (as I input them in the Inspector) of my laser beam which is colliding with alien spacecrafts:
var arrayOfColliderTags : Array = new Array("aaa", "bbb", "cccc", "ddd");
and I want the alien spacecraft that I attach this script on, to do something when my laser beams tag is NOT one of the aforementioned Arrays tags. So I say:
if (!col.gameObject.tag in arrayOfGoodColliders){
... do something...
}
I am a beginner, this might seem really basic for most of you, but this script doesnt do anything... Does it have to do with the fact that the Tag is a String? Thanks for reading :-)
I've never seen do used outside do..while , or in used outside for each ... in .... constructions actually. So either this is really interesting or very wrong.
I don't think it's wrong, because I copied the 2 example lines at the beginning of my question from tonyd's Newbie Guide to Unityjavascript: http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)?highlight=conditions
Answer by Mike 3 · Dec 16, 2010 at 06:47 PM
Using the spanking new syntax I just learned, it should be:
if (!(col.gameObject.tag in arrayOfGoodColliders)){
//... do something...
}
The code before was very likely evaluating !col.gameObject.tag to false, then looking for false in the array