Javascript (:) colon

Ok guys, very sorry if this doesn’t fit anywhere but I gotta know.
What the hell does the : do in javascript/unityscript?

For example:

var backDrop:Texture2D; //HERE
var windowPosition:Vector2=Vector2(200,200);
var windowSize:Vector2=Vector2(96.0,96.0); //AND HERE
var itemIconSize:Vector2=Vector2(32.0,32.0); //AND HERE
var updateListDelay=1.0;
var lastUpdate=0.0;//last time we updated the display.
var UpdatedList:Transform[];
var associatedInventory:Inventory; //LASTLY, HERE

And bonus question, how would one translate that into Boo?

Boo is based on Python (which was primarly a script too). I would think it is used inside Unity since you can see it mentioned on some type of errors in the console. BUt apart from that it is barely used and as barely used no one starts with it (vicious circle).

–

2 Answers

2

The : and the thing that follows it enforce a ‘type’ on that variable. Without it, it’s just a generic object. With it, you know that something is really a Texture2D or Vector2 or Transform etc.

Used in a function it indicates the return type. Just complementing the answer, you knew that.

–

my kid uses boo when we play peepo, can’t help with that.

In unity’s take on javascript the colon : is used like “new” is used for declaring object types in what the rest of the world call javascript.

Declarations of a data type is rare in javascript and mostly used for array objects (e.g.

var stuff = new Array(); 

In normal javascript most things are objects including functions. So the use of typing is rare

see how most of the web interprets javascript below…

http://www.w3schools.com/js/js_datatypes.asp

I find it easier not to think of unity javascript as javascript, so I think of it as unityscript.

Even so I like the possibilities of explicit typing in unity’s javascript, it makes the code easier to read IMHO, its quite easy to get yourself in a mess with strings and number data types in javascript “proper”. Very rarely need to debug simple type issues if at all in Unity.