Welcome to %s forums

BrainModular Users Forum

Login Register

need help to make a script

I need help on a Patch
Post Reply
joffo78
Member
Posts: 1033
Contact:

Unread post by joffo78 » 08 Mar 2011, 23:23

Hello

I'm working on a patch to make sequencial mouvements and i like to display some value of an array on a matrix module.
i like the approach of the script create comma text but i don't want to have to connect each output of the array on one integer to string and each integer to string on the create comma text entries .
more i have 120 value to connect.
So i wonder if someone could help me (or doing for me) a script which had one array input to get several value and make there a comma text.
thank you.

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 09 Mar 2011, 00:26

hi joffo,
here is one exemple, but it's a bit unclear for me how to dynamically alter tstringList lenghts (anyone?), so it has a fixed max capacity ( i don't understand the use of Tstringlist.capacity...)
you can easy edit if need more values.

Code: Select all

//////////////////////////
// Array values (INTEGERS) to commaText
/////////////////////////
CONST MAX_ITEMS = 128;
var ArrayIn, CommaOUT: Tparameter;
var SL1: TstringList;
/////////////////////////////
procedure init;
var i: integer;
begin
  ArrayIn:= CreateParam('ArrayIn', PtArray);
  SetIsOutput(ArrayIn,False); SetMin(ArrayIn,0); setMax(ArrayIn,MAXINT);

  CommaOUT:= CreateParam('CommaOUT',PtTextField);
  setisINPUT(commaOut,false);
   
  SL1:= Tstringlist.create;
  SL1.commatext:='';
  for i:= 0 to MAX_ITEMS -1 do begin SL1.add(' ');end;

END;//INIT
///////////////////////////////////////////
Procedure Callback(N:integer); 
var i, L: integer;
begin
      if (n=ArrayIn) then begin
         L:= getLength(ArrayIn);
         if L< MAX_ITEMS then begin
            For i&#58;= 0 to L-1 do begin
               SL1.strings&#91;i&#93;&#58;= IntToStr&#40;trunc&#40;getDataArrayValue&#40;ArrayIn,i&#41;&#41;&#41;;
            end;
         //Strace&#40;SL1.commatext&#41;;
         setStringValue&#40;CommaOut,SL1.commatext&#41;;
       end;
      end;
END;//CB
////////////////////////////////////////
Procedure Destroy;
begin
SL1.free;
end;
///////////////////////////////

joffo78
Member
Posts: 1033
Contact:

Unread post by joffo78 » 09 Mar 2011, 00:37

hi
thank you 23fx23
and if you can have a look on my second question i think it can be very usefull.
ps. i don't understand at all what Tstringlist.capacity is

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 09 Mar 2011, 02:42

yup ive just seen your other question and showed ya a patch solution;), ill try to make a script later.

sorry lol never mind about tstringlist ( a delphi script object, kind of array of strings, or simply what we call a 'list' used to manipulate commatexts and elements). I was more asking to some eventual scripter reader if would know how to deal with their length, but now i remember martignasse had conclued we had to fill them first with various or blank text, so here it may not adapt to arrayIn length if it changes over time, so it is 'pre-filled-formated' of 128 elements of blank text, then will replace the items by array values. (but then i don't see what would be the use of the funtion tstringlist.capacity..., something i felt strange..)

but you shouldn't worry att all about that to use it ;)

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

Unread post by bsork » 09 Mar 2011, 08:13

About TStringList, you don't have to fill it up like you do in Init. Just use SL1.Add(IntToStr(trunc(getDataArrayValue(ArrayIn,i)))) in a loop in Callback. That way you also don't have to think about MAX_SIZE as the array length will govern the length of the commatext.

No need to initialize SL1.Commatext right after Create either, it's empty anyway.
Bjørn S

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 09 Mar 2011, 10:12

ok cool, thanks bsork.

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests