Welcome to %s forums

BrainModular Users Forum

Login Register

Scripting and Array length

I need help on a Patch
Post Reply
antwan
Member
Posts: 164
Contact:

Unread post by antwan » 24 Oct 2008, 13:03

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

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 24 Oct 2008, 22:14

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.
Bjørn S

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 25 Oct 2008, 10:15

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...

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 28 Oct 2008, 10:33

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

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 28 Oct 2008, 11:40

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.
Bjørn S

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 28 Oct 2008, 12:19

Ok, that sounds like an interesting solution.
I will have a look at the Random Pattern Array to get the idea.

Cheers,

antwan

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests