Welcome to %s forums

BrainModular Users Forum

Login Register

Scripting: Outputting a rapid flow of values

I need help on a Patch
Post Reply
antwan
Member
Posts: 164
Contact:

Unread post by antwan » 09 Apr 2008, 13:10

Hi,

There's something i'm forgetting, i'm sure...
But it's a while since I've last been scripting. What I'm wondering is how to make the script output a fast flow of numeric values. I tried achieving that by using a for-loop, like:

for i := 0 to 7 do begin
SetValue(output, i);
end;

What I hoped to get with this is the values 0, 1, 2, 3, 4, 5, 6 and 7 in rapid succession in the outlet called "output". What I infact get in that outlet is 0 and then 7.

What am I missing. My skills are rusty! :)

Thanks,

antwan

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

Unread post by bsork » 09 Apr 2008, 13:48

Unless I've missed out on something, a single output of a script (or for that matter any module), will only send out one value per execution block. The only exception being arrays of various kinds, but they too only send one array at the time.

You have to rewrite the script to something like this:

Code: Select all

i := i + 1;
if (i = 7) then 
  i := 0
else
  i := i + 1;

SetValue(output, i);
Bjørn S

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 09 Apr 2008, 14:26

thanks,

yes that seems to do the trick. but building upon this... what if i want that to happen once under some condition: let's say if this and that variable is 1 then output numbers from 0 to 7.
Just putting that part of code within a if-phrase clearly wont work because it is no longer a loop of any kind...

thanks again,

antwan

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

Unread post by bsork » 09 Apr 2008, 15:31

I'm not sure if I understand how you want it to operate, but if for instance you want the values to be generated only as long as some switch is on, and that it should start from 0 each time, here's an example:

Code: Select all

var b boolean; // switch already on?
var i integer;
...
if (trunc(GetValue(input)=1)) then begin
   if (NOT b) then begin
      i := -1;
      b := true;
   end;
   i := i + 1;
   SetValue(output, i);
   if (i = 7) then 
      i := -1;
end
else begin
   b := false;
end;
Bjørn S

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 09 Apr 2008, 17:18

Hi,

It took me a while, but now I finally got it. Now I understand the logic behind it. Thanks man.

antwan

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

Unread post by bsork » 09 Apr 2008, 23:03

I too struggled a bit getting my head around programming stuff like that in the beginning with Usine. I work as a programmer doing business/database software and practically never have to deal with doing things step by step like this. It's always something that triggers some bit of code, and that code bit does its thing till it's finished. ...or crashes...
Bjørn S

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests