Hi, I have a script that populates an Array in Start(): Code (csharp): private var letters = new Array(); letters[0] = "A"; letters[1] = "B"; letters[2] = "C"; letters[3] = "D"; letters[4] = "E"; letters[5] = "F"; letters[6] = "G"; letters[7] = "H"; letters[8] = "I"; letters[9] = "J"; letters[10] = "K"; letters[11] = "L"; letters[12] = "M"; letters[13] = "N"; letters[14] = "O"; letters[15] = "P"; letters[16] = "Q"; letters[17] = "R"; letters[18] = "S"; letters[19] = "T"; letters[20] = "U"; letters[21] = "V"; letters[22] = "W"; letters[23] = "X"; letters[24] = "Y"; letters[25] = "Z"; letters[26] = "*"; In start() i do the following: Code (csharp): letter1 = PlayerPrefs.GetInt("letter1"); letter2 = PlayerPrefs.GetInt("letter2"); letter3 = PlayerPrefs.GetInt("letter3"); Debug.Log("Letter 1: " + letter1); Debug.Log("Letter 1: " + letters[letter1]); //Dies on this line This runs fine in the Editor, but when I run this code on the iPhone i get the following: Code (csharp): ExecutionEngineException: Attempting to JIT compile method '(wrapper dynamic-method) Boo.Lang.Runtime.RuntimeServices:RuntimeServices$op_Addition$System.String$System.String (object,object[])' while running with --aot-only. at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0 at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0 at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0 at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.DynamicDispatching.Emitters.DispatcherEmitter.CreateMethodDispatcher () [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.DynamicDispatching.Emitters.DispatcherEmitter.Emit () [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.EmitMethodDispatcher (Boo.Lang.Runtime.CandidateMethod found, System.Type[] argumentTypes) [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create () [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey13.<>m__7 () [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.RuntimeServices.InvokeRuntimeServicesOperator (System.String operatorName, System.Object[] args) [0x00000] in <filename unknown>:0 at Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) [0x00000] in <filename unknown>:0 at InitialsConfigScript.Start () [0x00000] in <filename unknown>:0 This happens on the second debug.log line. letter1=25, and letters[letter1] is where it shows this error. Anyone have any idea what I'm doing wrong? Thanks Felix
So I went ahead and made this change: private var letters : String[] = new String[27]; Now it works fine! What's the deal?
This code has always worked for me in the past. Then I upgraded to the latest Unity and it stopped working. Plus the docs say that you can set Arrays that way as well: From Code (csharp): function Start () { var arr = new Array (); // Add one element arr.Push ("Hello"); // print the first element ("Hello") print(arr[0]); // Resize the array arr.length = 2; // Assign "World" to the second element arr[1] = "World"; // iterate through the array for (var value : String in arr) { print(value); } } The strangest part is that it works in the Editor, but not in iOS.
To make the first bit of code you posted work, add this line between the variable declaration and where you start assigning values: letters.length = 27;
You get this error because you are trying to combine a string with an untyped value from an array. Unity iOS doesn' like this any more. To get around that you either need to use the internal typed arrays, As you already did. Or use (myarray[0] as String). Indeed your attempt would work in unity 1.5. Since 1.6 it became for some reason more and more strict, using JavaScript. I had to figure this the painful Way too.
Thanks Marjan. Makes sense now. Daniel: Because i'm lazy, and luckily i'm the only one who maintains this code.
It's perfectly legitimate to add elements like felixk's code was originally doing. i.e., Code (csharp): private var letters = new Array(); letters[0] = "A"; letters[1] = "B"; --Eric