- Home /
Question by
castor · Jul 21, 2015 at 04:04 AM ·
floattypecastingpragma
Javascript - How to get an error if typing int instead of float?
Basically what I want to do is make sure that if I pass a int into a function that requires a float, I will get an error. So something like this, should give me an error saying it's missing an argument.
function AddAction(selectedText : String, selectedFloat : float) {
//whatever
}
var selectedInt: int = 3;
//This should not work:
AddAction("Wait", selectedInt);
(Please don't tell me C# is much better, etc. I know it but it's not an option atm).
Comment
Try this?
selectedAction : function(), time : int
Unless time has to be a float...
Not sure what you wrote does? I just want to make sure that if I type a int I will get an error saying that function requires a float. (Also clarified the question, hopefully its more clear now)
Ah, oops, sorry, what was I thinking...
How about calling this function in AddAction()?
IsItAnInt(time);
function IsItAnInt(float num)
{
int i = $$anonymous$$athf.FloorToInt(num : float);
if (num != float(i) )
Debug.LogError("You entered an integer.");
}