04-18-2012, 01:00 PM
I've been trying forever to have an array in a class. It just won't work and will give me an error message. Is there any way to get an array into a class?
(04-18-2012, 01:00 PM)nemesis567 Wrote: [ -> ]will give me an error messageWhat error message? Always, always specify what error message pops up. Error messages are made to be read and understood, if not by you, then by the person helping you.
(04-18-2012, 01:47 PM)nemesis567 Wrote: [ -> ]It's not specific, and thus won't help that much: Error: Expected ;
The ; was expected where I put "HERE"
int[][] myArray"HERE"(5, int[](5));
int[][] x(4,int[](5)); -> int[][] x(4, makeArrayInt(5));
int[][] x(4,_x1); int[] _x1(5,0);
int[][] x(3,y); int[] y(3,0);
void OnStart()
{
x[0][0] = 1;
x[0][1] = 2;
x[0][2] = 3;
x[1][0] = 10;
x[1][1] = 20;
x[1][2] = 30;
x[2][2] = -3;
x[2][1] = -2;
x[2][0] = -1;
printArray(x,"Test");
printArray(y,"Test2");
}
void printArray(int[] ar, string name)
{
AddDebugMessage(name,false);
for(uint i =0; i<ar.length(); i++) AddDebugMessage("["+i+"]" + ar[i],false);
}
void printArray(int[][] ar, string name)
{
AddDebugMessage(name,false);
for(uint i =0; i<ar.length(); i++)
for(uint j =0; j<ar[i].length(); j++)
AddDebugMessage("["+i+","+j+"]" + ar[i][j],false);
}
int[][] a;
void OnStart()
{
a = int[][](4,int[](5,0));
}
(04-18-2012, 02:52 PM)nemesis567 Wrote: [ -> ]Unfortunetely it still gives the same error. Remember that the array is a member of the class.
void OnStart()
{
Test t;
printArray(t.array,"T");
}
class Test
{
int[][] array;
Test()
{
array = int[][](4,int[](5,0));
}
}
void printArray(int[][] ar, string name)
{
AddDebugMessage(name,false);
for(uint i =0; i<ar.length(); i++)
for(uint j =0; j<ar[i].length(); j++)
AddDebugMessage("["+i+","+j+"]" + ar[i][j],false);
}