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 W1k3 · Sep 26, 2014 at 08:26 PM · c#arrayobjectlist

How to properly create a 2 dimensional array of an object. [C#]

No errors in mono develop, but the console gives this for line 34:

error CS0178: Invalid rank specifier: expected ,' or ]'

I'm trying to create a List that holds 2 dimensional arrays of my placeholder objects. The object class just holds information in variables.

Here is my object class:

 using UnityEngine;
 using System.Collections;
 
 public class placeholder{
 
     public static bool exists = false;
     public static bool initialized = false;
     public static int priority = 0;
 }


Here is my entire script I'm working on; just in case. I suspect only line 34 for will be relevant however.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class floorbuilderv2 : MonoBehaviour {
 
     //room related
     public GameObject[] fourrooms = new GameObject[3];
     public GameObject[] threerooms = new GameObject[3];
     public GameObject[] tworooms = new GameObject[3];
     public GameObject[] onerooms = new GameObject[3];
     public GameObject[] startrooms = new GameObject[1];
 
     //flooor related
     int currentfloor = 0;
     public int Size_Increase_Factor = 5;
     List<placeholder[][]> existanceplaceholders = new List<placeholder[][]>(); 
  
     //placeholder[][] existance = new placeholder[10][10]; 
 
     //misc
     void Start () {
         transform.position = new Vector3 (0, 0, 0);
         buildnextfloor ();
     }
     
     void buildnextfloor(){
         int gridsize = currentfloor * 10;
         int starttile = Mathf.FloorToInt (gridsize/2);
         int roomquantity = (currentfloor + currentfloor) * Size_Increase_Factor;
         int roomsinitialized = 0;
         int priorityfactor = 1;
 
         placeholder[][] newplaceholder = new placeholder[gridsize][gridsize] ;
 
         existanceplaceholders.Add (newplaceholder); 
 
         creattile (starttile, starttile, 4, priorityfactor);
         priorityfactor ++;
 
         while(roomsinitialized < roomquantity){
         
             //int[] xcue = new int[gridsize];
             //int[] ycue = new int[gridsize];
 
             for(int i = 0; i < gridsize; i++){
                 for(int ii = 0; ii < gridsize; i++){
                     if(existanceplaceholders[currentfloor][i][ii].exists == true && existanceplaceholders[currentfloor][i][ii].initialized == false && roomsinitialized < roomquantity){
                         creattile(i,ii,0,priorityfactor);
                     }
                 }
             }
         }    
         Debug.Log ("test");
         Debug.Log ("test");
     }
     
     void creattile(int x, int y, int staticdoorcount, int priority){
         existanceplaceholders[currentfloor][x][y].exists = true; 
         existanceplaceholders[currentfloor][x][y].initialized = true;
         existanceplaceholders [currentfloor] [x] [y].priority = priority;
         int adjacents = 0;
 
         roomsinitialized ++;
 
         if (staticdoorcount > 0){
             if(staticdoorcount = 4){
                 existanceplaceholders[currentfloor][x+1][y].exists = true;
                 existanceplaceholders[currentfloor][x][y+1].exists = true;
                 existanceplaceholders[currentfloor][x-1][y].exists = true;
                 existanceplaceholders[currentfloor][x][y-1].exists = true;
             }
         }
 
         if ((int)Random.Range(1, 3) == 1){
             adjacents = 1;
         }
         else if((int)Random.Range(1, 3) != 1){
             adjacents = 2;
         }
         else{
             adjacents = 3;
         }
 
         int offsetx = 0;
         int offsety = 0;
 
         if(adjacents == 1){
             int attempts = 0;
 
             offsetx = setoffsetx();
             offsety = setoffsety(offsetx);
 
             while(existanceplaceholders[currentfloor][x +offsetx][y+offsety].exists == true){
                 offsetx = 0;
                 offsety = 0;
 
                 offsetx = setoffsetx();
                 offsety = setoffsety(offsetx);
 
                 attempts ++;
 
                 if(attempts > 3){
                     break;
                 }
             }
 
             existanceplaceholders[currentfloor][x +offsetx][y + offsety].exists = true;
         }
         else if(adjacents == 2){
             for(int i=0; i<2; i++){
                 int attempts = 0;
                 
                 offsetx = setoffsetx();
                 offsety = setoffsety(offsetx);
                 
                 while(existanceplaceholders[currentfloor][x +offsetx][y+offsety].exists == true){
                     offsetx = 0;
                     offsety = 0;
                     
                     offsetx = setoffsetx();
                     offsety = setoffsety(offsetx);
                     
                     attempts ++;
                     
                     if(attempts > 3){
                         break;
                     }
                 }
                 
                 existanceplaceholders[currentfloor][x +offsetx][y + offsety].exists = true;
             }
         }
         else if(adjacents == 3){
             for(int i=0; i<3; i++){
                 int attempts = 0;
                 
                 offsetx = setoffsetx();
                 offsety = setoffsety(offsetx);
                 
                 while(existanceplaceholders[currentfloor][x +offsetx][y+offsety].exists == true){
                     offsetx = 0;
                     offsety = 0;
                     
                     offsetx = setoffsetx();
                     offsety = setoffsety(offsetx);
                     
                     attempts ++;
                     
                     if(attempts > 3){
                         break;
                     }
                 }
                 
                 existanceplaceholders[currentfloor][x +offsetx][y + offsety].exists = true;
             }
         }
     }
 
 
 
     int setoffsetx(){
         if(Random.Range(1,2) == 1){
             int rnd = Random.Range (1, 2);
                 
             if(rnd == 1){
                 return -1;
             }
             if (rnd == 2) {
                 return 1;
             }
         }
         else{
             return 0;
         }
     }
     int setoffsety(int offsetx){
         if(offsetx == 0){
             int rnd = Random.Range (1, 2);
             
             if(rnd == 1){
                 return -1;
             }
             if (rnd == 2) {
                 return 1;
             }
         }
         else{
             return 0;
         }
     }
 
 
     void Update () {
     
     }
 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


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
2
Best Answer

Answer by Baste · Sep 26, 2014 at 08:39 PM

Check the official docs on multidimensional arrays. C#, unlike most other languages, uses a ,-notation to specify dimensions. So your line 34 should be:

 placeholder[,] newplaceholder = new placeholder[gridsize,gridsize] 


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 Baste · Sep 26, 2014 at 08:40 PM 1
Share

Also, you know, there's this .

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

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

Related Questions

properly initializing my arrays (C#) 2 Answers

How to Find all objects with Tag and List their Transforms? 4 Answers

Copy From Array to List without reference [C#] 2 Answers

Load Objects from a specific directory into a list? 0 Answers

Possible shader interference when updating matrix 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