Hello Guest  /  Join  /  Sign In  /  Get Desura
Avatar

TommyGoogle

Tom joined Dec 20, 2010

Sound designer/Game Developer based in South Yorkshire, UK

Posted by TommyGoogle on Aug 7th, 2012

ok - so here's some Unity Javascript kind of explaining what i've found out about arrays...

javascript code:
#pragma strict


var javascriptarray:Array = ["hello",9];//each is untyped, so this doesn't appear in inspector.. this can be resized at runtime - but sloooow...
//or.. var javascriptarray:Array = new Array();//needs = new Array(); if not giving data to begin with, or there will be no instance to add anything to..
javascriptarray.Push ("yep");//adds "yep" to next slot..


var arraylist:ArrayList = new ArrayList();//not viewable in inspector, CAN be resized, untyped, slower than built in...
arraylist.Add ("hello");//can be done here


var builtinarrayofints:int[] = [0,1,2,3,4,5,6,7];//has a type - so visible in inspector, and can be resized there - but not resizeable at runtime!!.
var builtin2darrayofints:String[,] = new String[3,9];;//a 2 dimensional array (3*9).. not visible in inspector..
builtin2darrayofints[2,8] = "last one!";//this can be done here (not in a function)!



function Start () {

//these come from the above things.
Debug.Log(arraylist[0]);//"hello"
Debug.Log(builtin2darrayofints[2,8]);//"last one!"



//you can have trouble with whether you are passing a value or a reference to the original data.. see below..

var integer:int = 0;
var arrayofints:int[] = [10,20];

Debug.Log(integer);
Debug.Log(arrayofints[0]);
Debug.Log(arrayofints[1]);


mangler (integer, arrayofints);


Debug.Log(integer);//still shows 0
Debug.Log(arrayofints[0]);//now shows 1000000
Debug.Log(arrayofints[1]);


}



function mangler (integer:int, array:int[])
{
integer = 1000000;
array[0] = 1000000;

}
 
Post a Comment
click to sign in and comment

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Offline Since
Mar 28, 2013
Country
United Kingdom United Kingdom
Gender
Male
Age
33
Contact
Private Message
Blog
Browse
Blogs