I have a list that holds 2 dimensional arrays. When I try to accesses one of my objects, it’s out of range. setting all indexes to 0 yields the same result so I can only assume something isn’t initialized properly. line 21, and line 41-47 are my initialization.
Here is the start of my code. the error is on line 74, where I have temporarily set all indexes to 0.
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];
//settings
public GameObject TestRepresent;
public float distance = 10f;
//flooor related
int currentfloor = 0;
public int Size_Increase_Factor = 5;
List<placeholder[,]> existanceplaceholders = new List<placeholder[,]>();
int roomcount = 0;
int initialisations = 0;
//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 priorityfactor = 1;
roomcount = 0;
initialisations = 0;
existanceplaceholders.Add(new placeholder[gridsize,gridsize]);
for (int i=0; i < (gridsize); i++) {
for(int ii =0; i < gridsize; i++){
existanceplaceholders[currentfloor][i, ii] = new placeholder();
}
}
////////////////////////////////////////////////////////////////////////////////
creattile (starttile, starttile, 4, priorityfactor, gridsize);
priorityfactor ++;
while(true){
int[] xcue = findnextcue(gridsize, true);
int[] ycue = findnextcue(gridsize, false);
for(int i =0; i < initialisations; i++){
if(roomcount < roomquantity){
creattile(xcue_, ycue*, 0, priorityfactor, gridsize);*_
* }*
* else{*
* break;*
* }*
* }*
* if(roomcount >= roomquantity){*
* break;*
* }*
* }*
* buildnextfloorfaze2(gridsize);*
* }*
* void creattile(int x, int y, int staticdoorcount, int priority, int gridsize){*
* existanceplaceholders[0][0, 0].exists = true;*
* existanceplaceholders[currentfloor][x, y].initialised = true;*
* existanceplaceholders [currentfloor] [x, y].location = generatecoordinates (x, y, gridsize);*
* roomcount ++;*
* existanceplaceholders [currentfloor] [x, y].priority = priority;*
* int adjacents = 0;*
* 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;*
* }*
* }*
This is the code for my object:
using UnityEngine;
using System.Collections;
public class placeholder{
* public string type;*
* public int priority;*
* public Vector3 location;*
* public bool exists = false;*
* public bool initialised = false;*
* public bool isphysicle = false;*
* public bool hasdoorconections = false;*
}