So I'm beginning to use JavaScript with a new gaming platform I'm trying out and LOVE the interface. It's making everything so easy compared to the in the garage type setup I'm used to. Learning JavaScript has been pretty easy so far but I've hit a snag with typeof.
private var Playing : boolean = false;
function PlayKeys(keys,times)
{
if(!Playing)
{
Playing = true;
Debug.Log(typeof(times)); //priming typeof unsure why but it makes the code work
Debug.Log(typeof(float));
Debug.Log(typeof(float[]));
if(typeof(times) == typeof(float[]))
{
AnimateKeysAndTimes(keys,times);
print("Keys & Time"); //Debug Code
}
else if(typeof(times) == typeof(float))
{
AnimateKeysConstantTime(keys,times);
print("Constant Time");
}
else
{
print("Failure");
Playing = false;
return;
}
}
}
Animation Code works like a dream and uses coroutines so I can put them in branch statements without making everything a convoluted mess. The issue is that I want one function that is "overloaded" for different types of animations. However, for javascript to do this I have to typecheck the variables myself since javascript allows dynamic typing. When I do typeof(timer) if it's a float I get a string "System.Single" if it's an Array I get "System.Single[]". However, typeof(timer) == "System.Single" when timer is a float won't evaluate to true ... kk .... However, I found if I primed the typeof declarations typeof(timer), typeof(float), typeof(float[]) I can than compare them and get true ..... this confuses me to no end. I think i'm misunderstanding how to use typeof and need someone with a bit more experience to tell me why this works.