Array Indexes in user defined Functions

3.73K viewsScripting
0

Hi,

I am developing user defined functions similar to this one:

[code:cjh13wr1]
double inputArrayTest(double[] a, int rowCount, int colCount)
{
def int sizeA = a.length
def int z = 0

def double[][] arrayA = new double[rowCount][colCount]

for (int i = 0; i < rowCount; i++)
{
for (int j = 0; j < colCount; j++)
{
arrayA[i][j] = a[z]
z++
}
}

// print “”hi””

// Test:
return a[2]
}
[/code:cjh13wr1]

When I access a value within the input array a this way:

[code:cjh13wr1]

// ... code

a[2]

// ... code

[/code:cjh13wr1]

then it works.

But when I try to access a value with the input array a like this:

[code:cjh13wr1]

// ... code

def int index = 0
a[index]

// ... code

[/code:cjh13wr1]

then I get a #SCRIPT entry in the testing matrix.

Is this a bug? Normally it is no problem in Groovy to access a value within an array with a[variable].

You can take the attached file “”InputArrayTest.model”” as an example.

Many thanks for clarification.

All the best,
Dominik

0

Problem solved, the bug was me…!

The input value for colCount was too big and exceeded the array size.

It’s nice when the problems are that simple…

dom

You are viewing 1 out of 1 answers, click here to view all answers.