Typing a value, not a var, syntax in js?

Hi to all! Silly sintax problem: I need to pass a UInt16 value to a function. How can I do it without defining a UInt16 var before?

For the moment I have to do this :

var one : UInt16 = 1;
var oneUInt16Bytes : Byte[] = BitConverter.GetBytes(one);

Many thanks!

I think the only way in UnityScript is to use a temp variable since UnityScript doesn’t have a value-type cast operator (only the as-cast which only works for reference types).

Implicit casting doesn’t help since the BitConverter have an overloaded function for every type. To enforce a uint16 parameter you need to pass a variable of that type.

ps. It would be better when you include the line of code you’re trying to get to work. Feel free to edit your question.

Well just do:

MyFunction( 3 );

If the signature of MyFunction is

MyFunction( UInt16 val );

Then it will be implicitly converted (I guess, since it is so in C#). If it is not the case (compilation or runtime raising a warning or an error), then cast it:

MyFunction( (UInt16) 3 );