Multi-dimensional Arrays

mbowdich
Posts: 209
Joined: Tue Oct 05, 2010 10:54 am

Multi-dimensional Arrays

Post by mbowdich » Tue Jul 12, 2011 10:58 pm

I am having trouble working with multidimentional arrays, specifically string arrays. The compiler fails if trying to define it as per the angelscript manual:

Code: Select all

//A 10 x 10 array
string [][] str (10, string [] (10));
I found that it does not allow default values:

Code: Select all

//A 10 x 2 array with default value of "a"
string [][] str (10,"a");
However, it will allow the creation of multidimentional array with or without a length, but the execution halts when attempting to insert data.

Code: Select all

//Theoretical 10 x 2 array
string [][] str (10);
str [0][0] = "test"; 
This compiles correctly, but it fails in execution and stops processing anything else in the script. The only thing I can think of off hand is that it is 10 elements in length, but 0 elements wide, effectively creating a non-existant array. The same thing holds true for even more dimensions:

Code: Select all

string [][][][][] str (10);
This also makes it through the compiler, but cannot be populated.

A 1 dimentional array works with no apparent issues:

Code: Select all

string [] str (10);
str [0] = "who";
str [1] = "what";
jtabb
Enovation Controls Development
Enovation Controls Development
Posts: 37
Joined: Mon Apr 04, 2011 8:59 am

Re: Multi-dimensional Arrays

Post by jtabb » Fri Jul 15, 2011 1:49 pm

mbowdich,

This took a bit for me to figure out.

I tried the different syntax from the angelcode manual:

Code: Select all

  int[][] a;                // An empty array of arrays of integers
  int[][] b = {{1,2},{3,4}} // A 2 by 2 array with initialized values
  int[][] c(10, int[](10)); // A 10 by 10 array of integers with uninitialized values
As you saw, they pass by the compiler but only the middle method, where I initialized all values would work. Once initialized, you can repopulate the specific values.

With a text gauge named TW_1 this worked:

Code: Select all

	string[][] strA = {{"",""},{"",""}};
	int ID;
		
	strA[0][1] = "test";
	ID = ScreenObjectID("TW_1");
	setTextWidgetText(ID, strA[0][1]);
	processScreenApi();
I have captured this bug in our system for us to address.

Thanks!
jtabb
FW Murphy Development Team
mbowdich
Posts: 209
Joined: Tue Oct 05, 2010 10:54 am

Re: Multi-dimensional Arrays

Post by mbowdich » Fri Jul 15, 2011 3:10 pm

Thanks for looking into it, but it still will not do what I need. I do not know the array size at compile time, it is dynamically created based on a file size, so I really need the 3rd syntax to work.

Code: Select all

string [][] strA (size, string [](8)); 
//size is the length of the open file divided by 8