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 secondry2 · Jan 02, 2014 at 02:04 AM · arraygameruntimeate

Problem reading from array at runtime

Ok, so basically I am making a game engine, and am having it so it reads from a code file at runtime. This is a short snippet that is causing the problem: (varList is a string, varArray is an array, I am splitting spaces to read the code file, so str is the string after the first space, the cases is the word before the first space)

 case "var":
             varList = varList + str + "|";
             varArray = varList.ToString().Split("|"[0]);
             
         case "getkey":
             var varIndex : int = 999;
             var error : boolean = false;
             var isDone : boolean = false;
             for (var iCount : int = 0; iCount < varArray.Length; iCount++) {
                 
                 if (varArray[iCount] == str && isSub && error == false && isDone == false) {
                     
                     varIndex = iCount;
                     error = false;
                     isDone = true;
                     
                 }
                 
             }
             
             if (error || isDone == false || varIndex == 999) {
                 
                 print("Variable, '" + str + "' not found!");
                 
             } else {
                 
                 var key;
                 
                 while (key == "") {
                     
                     key = Input.anyKeyDown;
                     
                 }
                 
                 print("Key pressed : " + key.ToString());
             }
             break;

sorry, formatting a bit messed up, but basically its throwing this error repetitively: NullReferenceExceptioon: Object reference not set to instance of an object Boo.Lang.Runtime>RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs System.Object rhs)

Referring to the line of code: varList = varList + str + "|";

Comment
Add comment · Show 4
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 landon912 · Jan 02, 2014 at 02:51 AM 0
Share

Print out both "str" and "varList" to find which one is null.

avatar image secondry2 · Jan 02, 2014 at 02:55 AM 0
Share

Thanks for the reply, this is my new 'var case' and it doesnt get up to the printing out of str and varList

     case "var":
         varList = varList + str + "|";
         varArray = varList.ToString().Split("|"[0]);
         
         print(str);
         print(varList);
avatar image landon912 · Jan 02, 2014 at 02:59 AM 0
Share

Put it before the line with the error.

We need to see the whole script to help more man....

avatar image secondry2 · Jan 02, 2014 at 03:06 AM 0
Share

str=key varList=Null

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robhuhn · Jan 02, 2014 at 08:53 AM

You should declare varList with an initial value (empty string). Instead of something like private string varList; write

 private string varList = "";
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

20 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

Related Questions

Finding What Material Is On The Object Player Collided With. 1 Answer

Can I get the a list of the properties in a shader at runtime? 1 Answer

load images into an array runtime. 0 Answers

Initiate class array at start and assign class values. 0 Answers

what is the best way to implement minigames into my own full blown unity game. 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