In this script example from the manual, the value is only found if last one in array. Can anyone explain how to have it found if anywhere in array?
(I am VERY new to attempting anything with scripts, so any insight would be greatly appreciated!)
////////////////////////////////////////////////////
// Check if a value is in the array
/////////////////////////////////////////////////////
var Arr, Found, Valsearch : Tparameter;
Procedure Init;
BEGIN
Arr := CreateParam('ArrayIn',PtArray);
setisOutput(Arr,false);
ValSearch := CreateParam('Value to search',PtDataField);
setisOutput(Valsearch,false); setvalue(valsearch,1);
Found := CreateParam('value found',PtSwitch);
setisInput(Found,false);
END;
//////////////////////////////////////////////////////////////////////
Procedure Callback (n: integer); // Scan the N inputs, and n pick the index of any input that changed to
// return result in same bloc.
var valFound : boolean; // "is our value found?" is a boolean = binary choice TRUE or FALSE type
// of variable
var i : integer; // integer used to scan thru the array elements.
BEGIN // Start the callback = check inputs changes
IF (n=Arr) then begin // if changes on Arr input, start
i := 0; // reset i (=index to scan)
valfound:=FALSE; // by default the value is not found
while ((not valFound) and (i < GetLength(arr))) do begin // do the check for each elmt among array
// length as long as value isn't found
valFound := (GetDataArrayValue(arr, i) = getvalue(Valsearch) ); // boolean result of the check we want to do ,
// TRUE if the array elmt(i) = our input value
i := i + 1; // increment the scanned elmt
end;
if valfound then begin //if the result of valfound is true, we set parameter to 1
setvalue(Found,1);
end
else begin //otherwise we set it to 0;
setvalue(Found,0);
end;
END; //end of subcheck process
END; // END of callback
'Check for Value in Array' script not working
mm thats strange i did this one a while back, checked here it work as espected, if i put 0.5 in middle of array and looking for 0.5 it will be switched on as found for exemple.
what value are you searching?
what value are you searching?
I'm searching integers between 1-128. Tried 0.5 too, but same thing, only found if last value... (Fwiw, I'm using 32-bit HH2 w/Windows)
OK, the 64-bit version works so it appears to be a bug in 32-bit HH2/HH3.
Confirmed on the 32 bit version Only
I'll take a look.
But here is a workaround :
I'll take a look.
But here is a workaround :
Code: Select all
////////////////////////////////////////////////////
// Check if a value is in the array
/////////////////////////////////////////////////////
var Arr, Found, Valsearch : Tparameter;
Procedure Init;
BEGIN
Arr := CreateParam('ArrayIn',PtArray);
setisOutput(Arr,false);
ValSearch := CreateParam('Value to search',PtDataField);
setisOutput(Valsearch,false); setvalue(valsearch,1);
Found := CreateParam('value found',PtSwitch);
setisInput(Found,false);
END;
//////////////////////////////////////////////////////////////////////
Procedure Callback (n: integer); // Scan the N inputs, and n pick the index of any input that changed to
// return result in same bloc.
var valFound : boolean; // "is our value found?" is a boolean = binary choice TRUE or FALSE type
// of variable
var i : integer; // integer used to scan thru the array elements.
BEGIN // Start the callback = check inputs changes
IF (n=Arr) then begin // if changes on Arr input, start
i := 0; // reset i (=index to scan)
valfound:=FALSE; // by default the value is not found
while ((not valFound)
and (i < GetLength(arr)))
do begin // do the check for each elmt among array
// length as long as value isn't found
if (GetDataArrayValue(arr, i) = getvalue(Valsearch) )
then valFound := TRUE;// boolean result of the check we want to do ,
// if valfound then itrace(i); // TRUE if the array elmt(i) = our input value
i := i + 1; // increment the scanned elmt
end;
if valfound then begin //if the result of valfound is true, we set parameter to 1
setvalue(Found,1);
end
else begin //otherwise we set it to 0;
setvalue(Found,0);
end;
END; //end of subchec
end;Olivier Sens
www.brainmodular.com
www.brainmodular.com
Who is online
Users browsing this forum: No registered users and 83 guests
