Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array in class
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#6
RE: Array in class

The problem comes from the fact that angelscript treats the array initilisation as a function call, which it then doesn't permit in the global scope:
int[][] x(4,int[](5)); -> int[][] x(4, makeArrayInt(5));
One way to fix this is to just to take split the initialisation out so there are none of these function calls:
int[][] x(4,_x1); int[] _x1(5,0);

This works, as can be seen by running the following test:
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);
}

The other way is just to state the bounds in a constructor (classes) or the OnStart event:
int[][] a;

void OnStart()
{
   a = int[][](4,int[](5,0));
}

Edit: Forum decided to mess up the code tags horribly Sad
(This post was last modified: 04-18-2012, 02:53 PM by Apjjm.)
04-18-2012, 02:49 PM
Find


Messages In This Thread
Array in class - by nemesis567 - 04-18-2012, 01:00 PM
RE: Array in class - by Cranky Old Man - 04-18-2012, 01:08 PM
RE: Array in class - by nemesis567 - 04-18-2012, 01:47 PM
RE: Array in class - by Cranky Old Man - 04-18-2012, 02:05 PM
RE: Array in class - by nemesis567 - 04-18-2012, 02:41 PM
RE: Array in class - by Apjjm - 04-18-2012, 02:49 PM
RE: Array in class - by nemesis567 - 04-18-2012, 02:52 PM
RE: Array in class - by Your Computer - 04-18-2012, 03:06 PM
RE: Array in class - by nemesis567 - 04-18-2012, 03:11 PM
RE: Array in class - by Apjjm - 04-18-2012, 04:18 PM
RE: Array in class - by nemesis567 - 04-18-2012, 04:33 PM



Users browsing this thread: 1 Guest(s)