The script works fine but i can't set a default value for the 'operator' combo. Thanks for help
Jean-Jacques
//////////////////////////////////////////////////////
// A iif vbasic like
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Parameters declaration
//////////////////////////////////////////////////////
var A : Tparameter;
var B: Tparameter;
var isTrue: Tparameter;
var isFalse: Tparameter;
var outPut: Tparameter;
var operator: Tparameter;
//////////////////////////////////////////////////////
// initialisation procedure
//////////////////////////////////////////////////////
procedure init;
begin
operator := CreateParam('operator',ptListBox);
SetListBoxString(operator,'"A=B","A<B","A>B","A<>B"');
SetdefaultValue(operator,int(0)); // doesn't run !!!!!!!!!
SetIsinput(operator,false);
SetIsOutput(operator,false);
SetReadOnly(operator, true);
A := CreateParam('A',ptDatafield);
SetIsinput(A,true);
SetIsOutput(A,false);
B := CreateParam('B',ptDatafield);
SetIsinput(B,true);
SetIsOutput(B,false);
isTrue := CreateParam('isTrue',ptDatafield);
SetIsinput(isTrue,false);
SetIsOutput(isTrue,false);
isFalse := CreateParam('isFalse',ptDatafield);
SetIsinput(isFalse,false);
SetIsOutput(isFalse,false);
outPut := CreateParam('outPut',ptDatafield);
SetIsinput(outPut,false);
SetIsOutput(outPut,true);
end;
//////////////////////////////////////////////////////
// Main Loop procedure
//////////////////////////////////////////////////////
begin
case int(getvalue(operator)) of
0:if getvalue(A)=getvalue(B) then
setvalue(outPut,getvalue(isTrue))
else setvalue(outPut,getvalue(isfalse));
1:if getvalue(A)=getvalue(B) then
setvalue(outPut,getvalue(isTrue))
else setvalue(outPut,getvalue(isfalse));
2:if getvalue(A)<getvalue(B) then
setvalue(outPut,getvalue(isTrue))
else setvalue(outPut,getvalue(isfalse));
3:if getvalue(A)>getvalue(B) then
setvalue(outPut,getvalue(isTrue)) else
setvalue(outPut,getvalue(isfalse));
4:if getvalue(A)<>getvalue(B) then
setvalue(outPut,getvalue(isTrue)) else
setvalue(outPut,getvalue(isfalse));
end;
end.
An IIF vBasic like script
i find the good syntax :
i replace SetdefaultValue(operator,int(0)) with
SetValue(operator,0);
i replace SetdefaultValue(operator,int(0)) with
SetValue(operator,0);
finaly, the case doesn't run so i replace it with some if else
/////////////////////////////////////////////////////////////////
begin
if getvalue(operator)=0 then
if getvalue(A)=getvalue(B) then
setvalue(outPut,getvalue(isTrue))
else setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=1 then
if getvalue(A)<>getvalue(B) then
setvalue(outPut,getvalue(isTrue))
else setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=2 then
if getvalue(A)<getvalue(B) then
setvalue(outPut,getvalue(isTrue))
else setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=3 then
if getvalue(A)<=getvalue(B) then
setvalue(outPut,getvalue(isTrue)) else
setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=4 then
if getvalue(A)>getvalue(B) then
setvalue(outPut,getvalue(isTrue)) else
setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=5 then
if getvalue(A)>=getvalue(B) then
setvalue(outPut,getvalue(isTrue)) else
setvalue(outPut,getvalue(isfalse));
end.
/////////////////////////////////////////////////////////////////
begin
if getvalue(operator)=0 then
if getvalue(A)=getvalue(B) then
setvalue(outPut,getvalue(isTrue))
else setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=1 then
if getvalue(A)<>getvalue(B) then
setvalue(outPut,getvalue(isTrue))
else setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=2 then
if getvalue(A)<getvalue(B) then
setvalue(outPut,getvalue(isTrue))
else setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=3 then
if getvalue(A)<=getvalue(B) then
setvalue(outPut,getvalue(isTrue)) else
setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=4 then
if getvalue(A)>getvalue(B) then
setvalue(outPut,getvalue(isTrue)) else
setvalue(outPut,getvalue(isfalse));
if getvalue(operator)=5 then
if getvalue(A)>=getvalue(B) then
setvalue(outPut,getvalue(isTrue)) else
setvalue(outPut,getvalue(isfalse));
end.
I'm not using CASE much myself, but I think that if you had enclosed every part within BEGIN .. END it would work.
You really should use some variables here. All the GetValues do take more CPU than needed, and also makes the script less compact and a bit harder to read than what is really neccessary. Here's a compact version (sorry, couldn't resist it):
The same function could also be created quite easily using modules. For example the A=B, A<B etc modules connected to the val inputs on a Selector, with a combo box to the select for the operators. Add 1 to the output of the Selector and use that for select on another Selector to switch between the isTrue and isFalse values, or instead of using a second Selector you could use Stop Event Flow and Pass Event Flow modules.
BTW, in my example code, I've used BEGIN .. END in the final IF .. ELSE statement even if it as far as I can see really shouldn't be neccessary. That's because I got a compilation error without it, which it seems that I get more often than others when I compare my scripts to what others create. It's either compilation errors or wrong behaviour in some way or another... Go figure - must be bad karma or something.
You really should use some variables here. All the GetValues do take more CPU than needed, and also makes the script less compact and a bit harder to read than what is really neccessary. Here's a compact version (sorry, couldn't resist it):
Code: Select all
begin
operator := CreateParam('operator',ptListBox);
SetListBoxString(operator,'"A=B","A<B","A>B","A<>B"');
SetIsOutput(operator,false);
A := CreateParam('A',ptDatafield);
SetIsOutput(A,false);
B := CreateParam('B',ptDatafield);
SetIsOutput(B,false);
isTrue := CreateParam('isTrue',ptDatafield);
SetIsOutput(isTrue,false);
isFalse := CreateParam('isFalse',ptDatafield);
SetIsOutput(isFalse,false);
outPut := CreateParam('outPut',ptDatafield);
SetIsinput(outPut,false);
end;
var op : integer;
var out : boolean;
var fa, fb : single;
begin
op := trunc(GetValue(operator));
fa := GetValue(A);
fb := GetValue(B);
case op of
0 : out := (A=B);
1 : out := (A<B);
2 : out := (A>B);
3 : out := (A<>B);
end;
if (out) then begin
SetValue(outPut, GetValue(isTrue));
end
else begin
SetValue(outPut, GetValue(isFalse));
end;
end.BTW, in my example code, I've used BEGIN .. END in the final IF .. ELSE statement even if it as far as I can see really shouldn't be neccessary. That's because I got a compilation error without it, which it seems that I get more often than others when I compare my scripts to what others create. It's either compilation errors or wrong behaviour in some way or another... Go figure - must be bad karma or something.
Bjørn S
Thank you for help. I'm a new Usine user and i wanted to try something
.
I'll complete it with more operators and perhaps download it for some "lazy" users !.
I'm sure that delphi is a powefull programming language and i'll try to make a visual user module (i have some ideas...). Congratulation and thanks to SensoMusic Team to give us a so complete software for only 50 €... I just by a Yamaha EzTP electronic trumpet and connect it yesterday to Usine... this was an extrem experience for me (not for my neighbours)
Jean-Jacques
(experimental music only)
I'll complete it with more operators and perhaps download it for some "lazy" users !.
I'm sure that delphi is a powefull programming language and i'll try to make a visual user module (i have some ideas...). Congratulation and thanks to SensoMusic Team to give us a so complete software for only 50 €... I just by a Yamaha EzTP electronic trumpet and connect it yesterday to Usine... this was an extrem experience for me (not for my neighbours)
Jean-Jacques
(experimental music only)
Who is online
Users browsing this forum: No registered users and 9 guests
