More UnityScript questions!

Hey,

Can anyone point me in the direction of the info I need to do the following:

  1. Multi-dimensional arrays.
  2. Pointers
  3. Arrays of Pointers
  4. Type definitions
  5. Enumerated types
  6. Constants

I’m struggling to find any of this info, but it’d make my code about 10,000 times slicker if I just had the answers!

Thanks! :slight_smile:

2/3) don’t exist in any of the script language. UnityScript is a .NET language as the other two as well so it only has type safe references
the only kind of pointer you can get, for usage in C++ plugins in Pro, are gotten through System.InteropServices.

If you were talking about references, then you just use var bla = someObject or var bla:someClass = someObject

OK, so there’s no real indirection. Never mind - what about the other stuff? Is that possible?

Yes, it is possible, although the syntax might be a little different.

  1. Type definitions
    use the “using” keyword.
    e.g. using ObjectList = System.Collections.Generic.List;

  2. Enumerated types
    public enum MyEnum { One = 1, Two = 2 }

  3. Constants
    I’m assuming you mean “#define
    you have to create a variable using const or readonly
    e.g. public const float PI = 3.1415926535f

for collections, you can look into .Net 2 collections, and everything there should be usable within unityscript. the syntax usually needs massaging to make it work, but everything should be available…

multi dimension arrays can be accomplished like this:
For a 10x10 array;

var matrix : Array;
var num = 10;

var s1 = “test”;
var s2 = “test2”;

matrix = new Array(num);

for (x=0;x<num;x++)
{
matrix[×] = new Array(1);
}

then you can access the elements of the array as your normally would.

matrix[0][1] = s1;
matrix[0][2] = s2;

these may be other ways of doing this, but the above is simple and easy to use.

hope this helps