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
-1
Question by gump74 · Jun 16, 2013 at 11:20 PM · javascriptgui

I am having an issue with returning an array

I am having an issue with rturning an array from a function and storing that in a var. the error is.

NullReferenceException: Object reference not set to an instance of an object screengui.SkillBox (Int32 x, Int32 y) (at Assets/screengui.js:26) screengui.OnGUI () (at Assets/screengui.js:15)

the following is my code.

 // from GUIData
 function GetData( prof:int, branch:int, level:int) : Object{
     ...
     var data = [ "", 0, "Novice Brawler", 88, 15 ];
     return data;
     ...
 }
 
 var data:Object[] = []; // line 25
 data = dataset.GetData( 0, 0, 0 ); //line 26

I have tried type casting data and the GetData function but it still errors out. This should be pretty simple but I have no idea why this is happening. All I want is to pass an array to a var. The Data var that is returned will be different based on the input of the function. Can someone tell me what I am missing?

Comment
Add comment · Show 3
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
avatar image BPR · Jun 20, 2013 at 07:41 PM 0
Share

Have you created an object "dataset" which has the class function "GetData" before?

Regards, BPR

avatar image gump74 · Jun 21, 2013 at 01:40 AM 0
Share

Type casting the varibles did not fix the issues,

Assets/screengui.js(25,18): BCE0018: The name 'object' does not denote a valid type ('not found'). Did you mean 'UnityEditorInternal.Object$$anonymous$$emoryInfo'?

not putting any type casting does not produce any compile errors however,it does produce a run time error

NullReferenceException: Object reference not set to an instance of an object screengui.SkillBox (Int32 x, Int32 y) (at Assets/screengui.js:25) screengui.OnGUI () (at Assets/screengui.js:15)

the current code is

 function GetData( prof:int, branch:int, level:int) {
     var data = [ "", 0, "Novice Brawler", 88, 15 ];
     return data;
 }
 
 var dataset:GUIData;  //line 24
 var data = dataset.GetData( 0, 0, 0 );  //line26
avatar image gump74 · Jun 21, 2013 at 01:47 AM 0
Share

@BPR No, I have not used this class before. This is the first time I have tried this kind of thing in javascript, I mainly use java so there is abit of a learning curve.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by gump74 · Jun 21, 2013 at 06:19 AM

I was able to figure it out. I tried moving GetData into the same file and calling it from there, that worked just fine. After recoding it back to separate files I was still getting the "NullReferenceException", I figured the dataset varible was not being properly instantiated. I read http://answers.unity3d.com/questions/24515/How-to-create-a-new-class.html; I found that to be quite helpfull. If there is anyone out there that runs into the same problem I did I will attach my new code so that others may find it useful.

 class GUIData {
 
     function GUIData() {
         
     }
     
     function GetData( prof:int, branch:int, level:int) {
         var data = [ "", 0, "Novice Brawler", 88, 15 ];
         return data;
     }
 
 }
 
 var dataset:GUIData = new GUIData();
 var data = dataset.GetData( 0, 0, 0 );


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
avatar image
0

Answer by Jessy · Jun 20, 2013 at 07:53 PM

Object with a capital letter is UnityEngine.Object; none of the stuff in your array is that. Use a lowercase o.

Also, you're returning Object and not Object[].

I really doubt you want to use that code, but those are your problems.

Comment
Add comment · Show 1 · 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
avatar image gump74 · Jun 21, 2013 at 05:46 AM 0
Share

@Jessy using object with a lowercase o is not valid.

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

16 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

Related Questions

Need help with my script 0 Answers

Limit on GUI Components? 0 Answers

Setting Scroll View Width GUILayout 1 Answer

How To Make Ammo & Realod for Gun & Spark for Gun ? 0 Answers

How Do I Create A Nested Function With Unity JavaScript? 1 Answer


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