Page 1 of 1

trouble with callback on matrix input

Posted: 02 Nov 2024, 19:39
by woodslanding
I have a script that aims to display matrix data in columns. It works fine for the text of the cells, but I recently tried to use it to reorder the cells values, and I'm having trouble with the array ins and outs.

Basically the output array only changes if the first item in the input array changes. I don't know why.. It sets the output array correctly for all items, but only when the first value in the input array has changed.

Thanks

Code: Select all

//////////////////////////////////////////////////////
// read matrix data newspaper style in columns
//e moon Nov 2022
////////////////////////////////////////////////////

const FAVTAG = '-';
var rowsIN, colsIN,ctIN,valsIN : Tparameter;
var ctOUT,dispCtOUT,valsOUT: Tparameter;

var gTextin, gTextOut, gDisplayText : TstringList;  
var row, col : integer;

// Globally enable/disable logging/////////////////////////////////////// 
const DTAG = 'matrix Sw> ';
const DBUG_ON = TRUE;
procedure debug(s: string); begin if DBUG_ON then strace(DTAG + s); end;
procedure iDebug(s: string; num : integer); begin debug(s + '= ' + intToStr(num)); end;
procedure fDebug(s: string; num : single); begin debug(s + '= ' + floatToStr(num)); end;
// Always log, whether debug is on or not.
procedure Error(s: string); begin strace('ERROR-' + DTAG + s); end;
procedure fError(s: string; num : single); begin strace('ERROR-' + DTAG + s + '= ' + floatToStr(num)); end;
//////////////////////////////////////////////////////////////////////////


procedure init;
begin   
    colsIN := CreateParam('col ct',ptDatafield,pioInput); 
    rowsIN := CreateParam('row ct',ptDatafield,pioInput);
    ctIN := CreateParam('ctext',ptTextField,pioInput);
    valsIN := CreateParam('values',ptArray,pioInput);

    ctOUT := CreateParam('ct out',ptTextField,pioOutput);
    dispCtOUT := CreateParam('display ct',ptTextField,pioOutput);
    valsOUT := CreateParam('values out',ptArray, pioOutput);

    ModuleColor($FF8E44AD); 
    gTextin.create; gTextOut.create; gDisplayText.create;
end;

// destroy
procedure Destroy; begin gTextIn.free; gTextOut.free; gDisplayText.free; end; 

procedure Callback(n:integer);
var i,j,len: integer;
var val: float;
var text,displayT: string;
var options: TReplaceFlags;
VAR values : ARRAY OF float;
begin
    
    //setArrayLength(values, 0); 
    //if n = valsIN then
    //begin
        len := valsIN.Length;
        valsOUT.Length(len);
        debug('vals in changed');
        j := 0;
        for col := 0 to (colsIN.asInteger - 1) do 
        begin
            for row := 0 to (rowsIN.asInteger - 1) do 
            begin 
                i := (colsIN.asInteger * row) + col;                                     
                valsOUT.asArray(j,valsIN.asArray(i));
                //values[j] := valsIN.asArray(i));
                //iDebug('setting output array position',j);
                //iDebug('to value',i);
                j := j + 1;
            end;
        end;
        gTextIn.clear; gTextOut.clear; gDisplayText.clear;
        gTextIn.setCommaText(ctIN.asString);

        options := [];
        
        for row := 0 to (rowsIN.asInteger - 1) do 
        begin
            for col := 0 to (colsIN.asInteger - 1) do 
            begin                                      
                i := (rowsIN.asInteger * col) + row;
                if i >= gTextIn.count then text := '' else text := gTextIn.getStrings(i);            
                gTextOut.add(text);
                //trim leading '-' from names for display
                if text.startsWith(FAVTAG) then displayT := StringReplace(text, FAVTAG,'', options) else displayT := text;
                gDisplayText.add(displayT);
                j := j + 1;
            end;
        end;
        ctOUT.asString(gTextOut.GetCommatext); 
        dispCtOUT.asString(gDisplayText.GetCommatext);
    //end;     
end;
Thanks,
-eric

Re: trouble with callback on matrix input

Posted: 02 Nov 2024, 19:54
by woodslanding
here's my test patch:
MatrixSwitchTestAgain.pat
(23.63 KiB) Downloaded 756 times
Again, if I change the value of the first cell, all arrayOUT values update correctly. But even though the callback method always gets called, it only works when the first arrayIN value changes.

Thanks

Re: trouble with callback on matrix input

Posted: 06 Nov 2024, 22:36
by SylvainT
Hi,
On my end, text doesn't react, but matrix input works as expected. 😉
Sorry, i haven't found time to dive into your script too much.
Sylvain

Re: trouble with callback on matrix input

Posted: 07 Nov 2024, 00:09
by oli_lab
Hi !
I tried to understand your patch, and I re-did it with modules from HH6
Hope it helps

Olivar
combine string and data.pat
(41.84 KiB) Downloaded 966 times

Re: trouble with callback on matrix input

Posted: 07 Nov 2024, 16:46
by woodslanding
Well, I re-wrote the script so it doesn't need to send an Array out. I still don't understand why it's not working, but I guess I don't need to know, for now.