Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by smweis1 · May 12, 2014 at 02:46 PM · javascriptmacpragma strict

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.

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\n");
 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+"\n");
  
  
  
 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[i];
 var swapIndex : int = UnityEngine.Random.Range(0, array.length - 1);
 array[i] = array[swapIndex];
 array[swapIndex] = temp;
 }
 return array;
 }

 


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by newfinalflashers · May 12, 2014 at 04:09 PM

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

var targetBuildingIndicesRemaining[];

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Implicit downcast and ArrayList 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Js , classes, and #pragma strict 0 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

JDK home issue (Mac to android) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges