Javascript Arrays in #pragma strict

EDIT: I’ve gotten the downcast warning to go away, but I’m still getting the NullRefException. This time for Line 89. No idea…Still works fine for Windows.

This is a second part to [this question][1].

My first question is rather basic: I THINK I’m an error I’m getting on a standalone Mac build is due to #pragma strict requirements. This is NOT an IOS build. Is that possible?

Here’s the issue I’m having: I have a Javascript array, targetBuildingIndicesRemaining (line 11) that is a list of numbers which refer to different locations that are coded elsewhere. The code runs fine in a Windows build, but when I build my environment for a standalone Mac, I get a “NullReferenceException” for line 100.

I get this error in the Mac build whether or not #pragma strict is on. But in #pragma strict I get a Warning in the Editor saying the int from targetBuildingIndicesRemaining is being downcast to an Object.

This leads me to believe that my Javascript Array I’m declaring is being treated as an Array of Objects in pragma strict, which is leading the Mac to throw a NullRefEx error.

My question is: How do I declare an Array that can be all integers, that can also be manipulated (e.g., functions similar to RemoveAt, Add, etc.)? Or, can I use int, and manipulate the integers within the list differently than I’m doing in the code?

#pragma strict
 
import System;
import System.IO;
 
var diamonds = List.<GameObject>();
var names = List.<String>();
var pointingDiamondIndex : int;
var facingDiamondIndex : int;
var targetBuildingIndex : int;
var targetBuildingIndicesRemaining : Array;
var targetBuildingIndicesRemainingIndex : int;
var pointingPromptObject : GameObject;
var waitingForClick : String;
var mainCamera : Camera;
var screenRay : Ray;
var currentPosition : Vector3;
var facingDiamondPosition : Vector3;
var pointingAngle : float;
static var dataDirectory : DirectoryInfo;
 
 
function Start() {
 
//load file-location
dataDirectory = new DirectoryInfo("C:");
WriteFile("out.txt","pointingDiamondIndex facingDiamondIndex targetBuildingIndex pointingAngle

");
pointingPromptObject = GameObject.Find(“PointingPrompt”);
mainCamera = Camera.main;

// populate arrays
diamonds.Add(GameObject.Find("Batty diamond"));
names.Add("Batty House");
diamonds.Add(GameObject.Find("Lynch diamond"));
names.Add("Lynch Station");
diamonds.Add(GameObject.Find("Harvey diamond"));
names.Add("Harvey House");
diamonds.Add(GameObject.Find("Golledge diamond"));
names.Add("Golledge Hall");
diamonds.Add(GameObject.Find("Sauer diamond"));
names.Add("Sauer Center");
diamonds.Add(GameObject.Find("Tobler diamond"));
names.Add("Tobler Museum");
 
startPointingSet(0);
}
 
function startPointingSet(startLandmarkIndex:int) {
if (startLandmarkIndex <= 5) {
pointingDiamondIndex = startLandmarkIndex;
var cc : CharacterController = GetComponent(CharacterController) as CharacterController;
// move to diamond
GetComponent(CharacterController).transform.position = diamonds[startLandmarkIndex].transform.position;
 
if (startLandmarkIndex == 0) facingDiamondIndex = 1;
else if (startLandmarkIndex == 1) facingDiamondIndex = 2;
else if (startLandmarkIndex == 2) facingDiamondIndex = 1;
else if (startLandmarkIndex == 3) facingDiamondIndex = 4;
else if (startLandmarkIndex == 4) facingDiamondIndex = 5;
else if (startLandmarkIndex == 5) facingDiamondIndex = 4;
 
 
targetBuildingIndicesRemaining = [0,1,2,3,4,5];
targetBuildingIndicesRemaining.RemoveAt(startLandmarkIndex);
Debug.Log("startPointingSet() targetBuildingIndicesRemaining: " + targetBuildingIndicesRemaining.join(","));
targetBuildingIndicesRemaining = shuffle(targetBuildingIndicesRemaining);
 
showPointingQuestion();
}
else {
// all done -- return to browser
Debug.Log("all done -- return to browser");
Application.ExternalCall("doneWithPointing");
}
}
 
function showPointingQuestion() {
if (targetBuildingIndicesRemaining.length > 0) {
targetBuildingIndex = targetBuildingIndicesRemaining[0];
// show instructions
pointingPromptObject.guiText.text = "Point to " + names[targetBuildingIndex];
}
else {
startPointingSet(pointingDiamondIndex + 1);
}
}
 
function Update() {
screenRay = mainCamera.ScreenPointToRay(Vector3((mainCamera.pixelWidth / 2), (mainCamera.pixelHeight / 2), 0));
Debug.DrawRay(screenRay.origin, screenRay.direction * 2000, Color.red);
Debug.DrawLine(screenRay.origin, diamonds[facingDiamondIndex].transform.position, Color.blue);
if (Input.GetKey ("escape")) {
Application.Quit();
}
 
}
 
function OnGUI() {
if (Input.GetButton ("Fire1")) {
if(targetBuildingIndicesRemaining.Count>0){
targetBuildingIndicesRemaining.RemoveAt(0);
Debug.Log("OnGUI() targetBuildingIndicesRemaining: " + targetBuildingIndicesRemaining.join(","));
 
screenRay = mainCamera.ScreenPointToRay(Vector3((mainCamera.pixelWidth / 2), (mainCamera.pixelHeight / 2), 0));
currentPosition = GetComponent(CharacterController).transform.position;
facingDiamondPosition = diamonds[facingDiamondIndex].transform.position;
pointingAngle = Vector3.Angle((facingDiamondPosition-currentPosition), screenRay.direction);
Debug.Log("pointing angle: " + pointingAngle);
 
// send pointing angle to the browser
Application.ExternalCall("recordPointingQuestion", pointingDiamondIndex, facingDiamondIndex, targetBuildingIndex, pointingAngle);
 
 
WriteFile("out.txt",pointingDiamondIndex+" "+ facingDiamondIndex+" "+targetBuildingIndex+" "+pointingAngle+"

");

Input.ResetInputAxes(); // we don't want this repeated multiple times
 
showPointingQuestion();
} else{
Application.Quit();
}
}
}
 
//new function for saving into file on disk
static public function WriteFile(fileName : String, data : String) {
var writer : StreamWriter;
var t : FileInfo = new FileInfo(dataDirectory.FullName + '/' + fileName);
writer = t.AppendText();
writer.Write(data);
writer.Close();
}
 
function shuffle(array : Array) {
var temp : int;
 
for (var i : int = 0; i < array.length; i++) {
temp = array*;*

var swapIndex : int = UnityEngine.Random.Range(0, array.length - 1);
array = array[swapIndex];
array[swapIndex] = temp;
}
return array;
}

_*[1]: http://answers.unity3d.com/questions/703049/custom-script-issue-from-pc-to-mac-not-ios.html*_

An array is to have two brackets at the end of the variable to symbolize what is inside it like this

var targetBuildingIndicesRemaining;