Page 1 of 1

Posted: 24 Oct 2008, 13:03
by antwan
Hi,

I'm confused about this little problem:
When I wire up a empty (size 0) array to the array-inlet of the simple example script, shown below, and an "execute" button to the execute-inlet, it claims that the length of the array is 1.
Here's the script to demonstrate:

Code: Select all

VAR pArray    : TParameter;
VAR pExecute  : TParameter;
VAR len       : integer;

// initialisation : create parameters

PROCEDURE init;
BEGIN
  pArray := CreateParam('Array in', ptArray); SetIsOutput(pArray, FALSE);
  pExecute := CreateParam('Execute', ptButton); SetIsOutput(pExecute, FALSE);
END;

BEGIN
  IF (GetValue (pExecute) = 1) THEN BEGIN
     len := GetLength(pArray);
     writeln(intToStr(len));
  END;
Why do you reckon?
Any help much appreciated.

antwan

Posted: 24 Oct 2008, 22:14
by bsork
This is a case for the boss... ;)

I know he has been doing a lot of stuff lately that has to do with zero length arrays and how to handle them etc.

Posted: 25 Oct 2008, 10:15
by senso
your are right, it's a bug. Will be corrected in the next version.

@bsork: you better know the scripting engine than me! really! The only difference is that I can take a look into the source code and know if eventually it's a bug...

Posted: 28 Oct 2008, 10:33
by antwan
Hi

Thanks for fixing this one; the scripting may go on!
I have another question though.

If I have code getting or setting values from/to inputs/outputs, for example:
GetLength(pArray)
Is there a way to somehow cast a string variable in the place of pArray. To make myself clear: if I have a string variable called currentInput containing either 'pArray' or 'pArray2', set elsewhere in the program, is there a way to use currentInput in the place of pArray, in this example. Obviously it doesn't work directly, but I'm wondering if there's some way to make it work?

Thanks, once again.

antwan

Posted: 28 Oct 2008, 11:40
by bsork
I don't know if you can use string variables the way you describe, but you can create arrays of in-/output parameters, and use an integer variable to access the right one.

There's a good example in the DataRandom GeneratorsRandom Pattern Array.script, where the ArrayOut variable is an array of tParameter. I've done the same thing in some of my add-ons, but I don't recall which right now.

Posted: 28 Oct 2008, 12:19
by antwan
Ok, that sounds like an interesting solution.
I will have a look at the Random Pattern Array to get the idea.

Cheers,

antwan