Scripting debug help
Working on my first script. It is a simple affair that outputs integers between two input values (loVal and hiVal).
I'm wondering if someone can offer a little advice as to why it doesn't output the numbers as expected:
/////////////////////////////////////
// Count
// Counts between loVal and hiVal (inclusive)
////////////////////////////////////
// parameters declaration
var reset, loVal, hiVal, blocsPerCount, count : Tparameter;
var i, c, lv, hv, bpc : integer;
// initialisation : create parameters
procedure init;
begin
reset := CreateParam('reset',ptButton);
SetIsOutput(reset,false);
hiVal := CreateParam('hiVal',ptDataField);
SetIsOutput(hiVal,false);
loVal := CreateParam('loVal',ptDataField);
SetIsOutput(loVal,false);
blocsPerCount := CreateParam('blocsPerCount',ptDataField);
SetIsOutput(blocsPerCount,false);
count := CreateParam('count',ptDataField);
SetIsInput(count,false);
SetReadOnly(count,true);
SetFormat(count,'%.0f');
SetValue(count,0);
end;
// Callback procedure
//Procedure Callback(N:integer);
//begin
//end;
// Global variables
//////////////////////////////
// main proc
//////////////////////////////
Procedure Process;
begin
if (GetValue(reset)=1)then
begin
SetValue(reset,0);
lv:=round(GetValue(loVal));
hv:=round(GetValue(hiVal));
bpc:=round(GetValue(blocsPerCount));
SetValue(count,lv);
for c:=lv to hv do
begin
itrace(c);
SetValue(count,StrToFloat(IntToStr(c)));
begin
for i:=0 to bpc do lv:=lv // this waits 4 blocs before incrementing c
end;
end;
end;
end;
Any help would be appreciated. Thanks.
I'm wondering if someone can offer a little advice as to why it doesn't output the numbers as expected:
/////////////////////////////////////
// Count
// Counts between loVal and hiVal (inclusive)
////////////////////////////////////
// parameters declaration
var reset, loVal, hiVal, blocsPerCount, count : Tparameter;
var i, c, lv, hv, bpc : integer;
// initialisation : create parameters
procedure init;
begin
reset := CreateParam('reset',ptButton);
SetIsOutput(reset,false);
hiVal := CreateParam('hiVal',ptDataField);
SetIsOutput(hiVal,false);
loVal := CreateParam('loVal',ptDataField);
SetIsOutput(loVal,false);
blocsPerCount := CreateParam('blocsPerCount',ptDataField);
SetIsOutput(blocsPerCount,false);
count := CreateParam('count',ptDataField);
SetIsInput(count,false);
SetReadOnly(count,true);
SetFormat(count,'%.0f');
SetValue(count,0);
end;
// Callback procedure
//Procedure Callback(N:integer);
//begin
//end;
// Global variables
//////////////////////////////
// main proc
//////////////////////////////
Procedure Process;
begin
if (GetValue(reset)=1)then
begin
SetValue(reset,0);
lv:=round(GetValue(loVal));
hv:=round(GetValue(hiVal));
bpc:=round(GetValue(blocsPerCount));
SetValue(count,lv);
for c:=lv to hv do
begin
itrace(c);
SetValue(count,StrToFloat(IntToStr(c)));
begin
for i:=0 to bpc do lv:=lv // this waits 4 blocs before incrementing c
end;
end;
end;
end;
Any help would be appreciated. Thanks.
Regards,
Scott
Scott
mmm dk if will solve the pb, but why do you type
SetValue(count,StrToFloat(IntToStr(c)));
instead of simply
SetValue(count,c); ? the string conversion and conversion back seems useless
also it seems you are trying to set 2 times the count value. the first seems ok
remember the 'for i = something to ' stuff is a loop operating within one single bloc, which seems not what you ned here.
if you vant some incremental count to occur per bloc in process,
you should not use some for i loop, but increment a value like
count:=count +1;
SetValue(count,StrToFloat(IntToStr(c)));
instead of simply
SetValue(count,c); ? the string conversion and conversion back seems useless
also it seems you are trying to set 2 times the count value. the first seems ok
remember the 'for i = something to ' stuff is a loop operating within one single bloc, which seems not what you ned here.
if you vant some incremental count to occur per bloc in process,
you should not use some for i loop, but increment a value like
count:=count +1;
Thanks 23fx23.
I tried "SetValue(count,StrToFloat(IntToStr(c)));" because "SetValue(count,c);" doesn't work.
What's weird is that the itrace shows the correct values for c. It just seems that the SetValue doesn't work properly.
I tried "SetValue(count,StrToFloat(IntToStr(c)));" because "SetValue(count,c);" doesn't work.
What's weird is that the itrace shows the correct values for c. It just seems that the SetValue doesn't work properly.
Regards,
Scott
Scott
Hi ahonoe!
It's like 23fx23 wrote... Your script is to fast. It has finished its work before the next bloc is calculated.
It is working, but it is simply to fast....
That's why you only see it with the itrace.
Here is an example how to work with "+1"
There is also shown, how you could change the counting speed in a simple way.
bloc_counter_with_max_value_and_refresh_speed
It's like 23fx23 wrote... Your script is to fast. It has finished its work before the next bloc is calculated.
It is working, but it is simply to fast....
That's why you only see it with the itrace.
Here is an example how to work with "+1"
There is also shown, how you could change the counting speed in a simple way.
bloc_counter_with_max_value_and_refresh_speed
Thanks percuson. While I now understand that my "count' is happening within a single bloc, I don't see how the example you pointed me to gets around this. I know I need to increment the counter only once per bloc, but I don't see any reference to "samples per bloc" in the example, so I'm not sure how to add a 'wait' to my script.
Are you saying that 'for i:=...' is calculated at a faster speed than 'i:=i+1'??? Surely that can be true?
Are you saying that 'for i:=...' is calculated at a faster speed than 'i:=i+1'??? Surely that can be true?
Regards,
Scott
Scott
Hi Scott!
let me explain:
the "for i:=..." calculates all within one bloc. (it jumpes back an calculates until the highest value of i - all within a bloc)
if you take "i := i + " the script calculates only the +1. Nothing else, because there is no jumping back in the script, like if you use "for". It finishes at the end of the script and waits for its next call (And keeps the calculated value of the +1).
When the script is called the next time (on the next bloc) it calclculates the next value (i := i + 1).
So you don't need a wait command to count up.
Slowing down the counting of your script is the next step.
e.g. you want to wait 100 blocs for the next counting up.
Maybe you can do it with a second variable "x" that counts up (also with + 1) from 0 to 100.
If the value is 100, set "x:=0". You make a loop this way with 100 steps.
Now you can trigger the upcounting of "i" to the value of "x".
Only if this value is "x=0" the counting up (i) is done.
But maybe you have another idea how to do this.....
in the demo script the slower counting up is done by dividing and rounding the value:
SetValue(counter, count div round(getValue(NB_blocs)));
This is also quite elegant, but maybe its more difficult to build in your script....
Are you saying that 'for i:=...' is calculated at a faster speed than 'i:=i+1'??? Surely that can be true?
And... no, it is not. It is slower because of calling a script on every bloc (like explained before)
I hope this was vivid enough and you can finish your first script!
let me explain:
the "for i:=..." calculates all within one bloc. (it jumpes back an calculates until the highest value of i - all within a bloc)
if you take "i := i + " the script calculates only the +1. Nothing else, because there is no jumping back in the script, like if you use "for". It finishes at the end of the script and waits for its next call (And keeps the calculated value of the +1).
When the script is called the next time (on the next bloc) it calclculates the next value (i := i + 1).
So you don't need a wait command to count up.
Slowing down the counting of your script is the next step.
e.g. you want to wait 100 blocs for the next counting up.
Maybe you can do it with a second variable "x" that counts up (also with + 1) from 0 to 100.
If the value is 100, set "x:=0". You make a loop this way with 100 steps.
Now you can trigger the upcounting of "i" to the value of "x".
Only if this value is "x=0" the counting up (i) is done.
But maybe you have another idea how to do this.....
in the demo script the slower counting up is done by dividing and rounding the value:
SetValue(counter, count div round(getValue(NB_blocs)));
This is also quite elegant, but maybe its more difficult to build in your script....
Are you saying that 'for i:=...' is calculated at a faster speed than 'i:=i+1'??? Surely that can be true?
And... no, it is not. It is slower because of calling a script on every bloc (like explained before)
I hope this was vivid enough and you can finish your first script!
Thanks percuson. I have been thinking about this for a few days now. Unfortunately I still don't understand why the example script runs more slowly.
Let me start with a basic question: does the example script execute only when there is a change to one of the inputs, or does it run every bloc? (the callback() procedure documentation says that it should only run when an input changes).
Let me start with a basic question: does the example script execute only when there is a change to one of the inputs, or does it run every bloc? (the callback() procedure documentation says that it should only run when an input changes).
Regards,
Scott
Scott
Hi Scott!
With the callback procedure you are right. The part of the script inside a callback procedure is only called once, if the corresponding input parameter has changed. But the demo script is working with the process procedure. So this is not the case.
When calculated with the Process Procedure, the script is calculated once on every bloc.
This means that it is calculated once from the beginning to the end.
if you use the '+1':
there is only one +1 in the script and the script is executed once a bloc.
So the result of the script at the end of the bloc is +1.
if you use the 'for' command:
the script is also executed once per bloc from the beginning to the end.
But the 'for' command makes a jumpback until its highest value is reached.
then it goes to the next line in the script.
That means that at a single script execution it calculates all values.
And at the end of the bloc, the result is the highest value...
I made a demo, explaining this more detailed and with very simple scripts:
Scripting Demo
With the callback procedure you are right. The part of the script inside a callback procedure is only called once, if the corresponding input parameter has changed. But the demo script is working with the process procedure. So this is not the case.
When calculated with the Process Procedure, the script is calculated once on every bloc.
This means that it is calculated once from the beginning to the end.
if you use the '+1':
there is only one +1 in the script and the script is executed once a bloc.
So the result of the script at the end of the bloc is +1.
if you use the 'for' command:
the script is also executed once per bloc from the beginning to the end.
But the 'for' command makes a jumpback until its highest value is reached.
then it goes to the next line in the script.
That means that at a single script execution it calculates all values.
And at the end of the bloc, the result is the highest value...
I made a demo, explaining this more detailed and with very simple scripts:
Scripting Demo
Who is online
Users browsing this forum: No registered users and 28 guests
