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 yxyx136 · Aug 29, 2014 at 12:05 PM · errorarray

Boo: Object reference not set to an instance of an object

Hey Guys, I tried to use multidimensional arrays in boo and it just threw this error:

 NullReferenceException: Object reference not set to an instance of an object
     GameScript.buildGrid () (at Assets/Scripts/GameScript.boo:28)
     GameScript.OnGUI () (at Assets/Scripts/GameScript.boo:40)

Here's my Code:

 import UnityEngine
 
 public class Card (System.Object):
     isFaceUp as bool  = false
     isMatched as bool = false
     public img = "robot"
 
 
 class GameScript (MonoBehaviour):
     cols as int = 4
     rows as int = 4
     totalCards as int = cols * rows
     matchesNeededToWin as int = totalCards * 0.5
     mathesMade as int = 0
     cardW as int = 100
     cardH as int = 100
     aCards as List
     aGrid as (Card, 2)
     aCardsFlipped as List
     playerCanClick as bool
     playerHasWon as bool = false
     
     def buildGrid():
         GUILayout.BeginVertical()
         for i in range(rows):
             GUILayout.BeginHorizontal()
             for j in range(cols):
                 card = aGrid[i,j]
                 if (GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW))):
                     Debug.Log(card.img)
                     
     def Start ():
         playerCanClick = true
         for i in range(rows):
             for j in range(cols):
                 aGrid[i,j] = Card()
     
     def OnGUI ():
         GUILayout.BeginArea (Rect (0,0,Screen.width,Screen.height))
         //buildGrid()
         GUILayout.EndArea()
 


Thanks in advance!

Comment
Add comment · Show 1
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 Kiwasi · Aug 30, 2014 at 02:13 AM 0
Share

Wow, that's the first time I've seen a boo script. Are you absolutely sure you want to use this language?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Landern · Aug 29, 2014 at 12:54 PM

You made the size of 2 for aGrid of type Card.

 aGrid as (Card, 2)

Your rows and cols are 4 each.

  cols as int = 4
  rows as int = 4

The for loop is using range(4) for both rows and cols.

 for i in range(rows):
   GUILayout.BeginHorizontal()
     for j in range(cols):
       card = aGrid[i,j]

aGrid doesn't have the range you're looking for.

disclaimer: haven't touched boo in years.

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 yxyx136 · Aug 29, 2014 at 09:54 PM 0
Share

Thanks for your answer! This could be the problem, but I don't know how to create 2- dimensional arrays in this language. This page describes that you can create a 2-dimensional array like that: aGrid as (Card, 2), but it didn't work. So if I would use aGrid as (Card, 4) it would create an 4-dimensional array?? (excuse me for my bad english, I'm still learning)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

When using input, array.Add replaces the last member 1 Answer

Error when trying to set variable with array 1 Answer

error for array functions 2 Answers

Argument is out of range in array 1 Answer

IndexOutOfRangeException: Array index is out of range 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