Welcome to %s forums

BrainModular Users Forum

Login Register

IML wiring several times?

I need help on a Patch
Post Reply
23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 02 Jun 2010, 22:46

Ive v got some pbs of IML wiring several times, I had my datas weird and finally discovered there was several wires on one,
while its not possible via classic patching, it is with iml, so the datas add together.
arf im turning around, any clues?
if a build buton is 1 imake var vcount:=1;
///////////////////////////////////////////////
Procedure WIRE_MSDWNARR;
BEGIN
for i:= 0 to nb_items -1 do begin
name:= 'cell'+IntToStr(i);
S:= S+'"'+'CREATE_LINK '+name+' '+''''+'mouse dwn'+''''+' MSDWNARR '+'INPUT'+intToStr(i)+'"'+',';
setStringValue(msg,S);
end;
END;
///////////////////////////////////////////////Process proc
if vcount = 1 then begin
count:= count+1;
if count = 1 then Crea_Mod;
if count = WaitBlocs*4 then WIRE_MSDWNARR;
if count > WaitBlocs*8 then begin
count:=-1;
vcount:=0;
end;
end;
///////////////////////////////////////////////////

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 02 Jun 2010, 22:55

strange, the console shows me this while processing, my names seems correct, it says it doesn't catch the var but it manage to wire.. i don't catch..:
..............
process msg : CREATE_LINK CELL6 mouse dwn MSDWNARR INPUT6
Var not found :CELL6
Var not found :mouse dwn
Var not found :MSDWNARR
Var not found :INPUT6
Add Connection
........................
I tried to make a manual single mess to debug with send usine message module and it says the same, but wire anyway,
but only one time. mmmmmmm

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

Unread post by bsork » 02 Jun 2010, 23:14

Shouldn't all names with spaces in them be enclosed with double quotes?
Bjørn S

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 02 Jun 2010, 23:25

In fact when using Lines Msg with module, the whole line need to be between doube quotes, so i tried but couldn't put my names
between double quotes as well, or the module interpreted two lines in same sentence. so ive tried to make them betwen 4 single quotes and that seems to work. . did you manage to put double quotes when using with module?

anyway the new system will be much easier, i suppose arg are considered as double quoted even if not...
for my multiple wires pb, i atlast got it fixed now like this:
///////////////////////////////////////////////
Procedure WIRE_MSDWNARR;
BEGIN
for i:= 0 to nb_items -1 do begin
name:= 'cell'+IntToStr(i);
S:= S+'"'+'CREATE_LINK '+name+' '+''''+'mouse dwn'+''''+' MSDWNARR '+'INPUT'+intToStr(i)+'"'+',';
end;
if i= nb_items-1 then begin // moded
setStringValue(msg,S);
end;
END;
///////////////////////////////////////////////
mmm that mean i must have lot of scripts that must process several times instead on one...i usually don't wait end and update
just like first., subbloc/blocs/time events operations are still a bit obscure for me.
I thought that when using "for i to" it was making subbloc ops, then setting the tparameter would only be possible on next bloc,
isn't it? or on first exemple, the output could be set/updated within a bloc? if i check the message in module, it seems not, I only see lines once. I tried to copy the text and if sending via button wire correcly once..
arf im happy it work but would soo like to understand....
do ya make kind of same end i check wait to send results, ?

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 03 Jun 2010, 04:19

AAAAAAAAAAAHHHH ok i think found where my pb was coming from:

i had several procedures using same S:=S+ for the string, but i was'nt reseting S, so i guess it picked up previous huge list oops
cool, nothing linked to sub bloc or bloc or iml i guess, a beginner error hehe.

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

Unread post by bsork » 03 Jun 2010, 09:06

Good you found the error - guess I should've seen that.

One tip is to use local variables for procedures and functions when possible; it's considered good programming practice and you don't have to think about resetting (unless you're reusing within the same method, of course). Reusing global variables has the benefit of using less memory, but in a typical script some extra variables here and there may use a kB or two, so it doesn't really matter. The program often gets more readable and more often than not easier to maintain and expand on.
23fx23 wrote:I thought that when using "for i to" it was making subbloc ops...
As you've probably have found out yourself, this isn't the case. Everything started within a block gets executed within that block. The only way to spread the execution of something over several blocks is to have some logic that takes care of when to do what, and it should be called from Process unless you have something outside of the script that triggers the executions through callbacks It can be timers (including counting blocks), some kind of incremental execution (if x=1 then doThis else if x=2 then doThat etc...), splitting a loop construct into smaller parts, etc.A typical example of the last one could be to do calculations on a 2-dimensional array, where you take all the elements of one of the dimensions within one block:

Code: Select all

VAR dim1 : Integer;
VAR arr ARRAY[0..15, 0..15] OF Single;
...
PROCEDURE Callback(N : Integer);
BEGIN
   // Some callback sets dim1 = 0;
END;

PROCEDURE Process;
    VAR dim2 : Integer;
BEGIN
   IF &#40;dim1 < 16&#41; THEN BEGIN
       FOR dim2 &#58;= 0 TO 15 DO
         arr&#91;dim1, dim2&#93; &#58;= _something_;
      dim1 &#58;= dim1 + 1;
   END;
END;
Not to be used for timing critical stuff, of course.
Bjørn S

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 03 Jun 2010, 14:38

thanks a lot for the tips, and the example is something i was just about to need. so that's very cool..
yeah i need to take that habit of making more independant variables, it was really a frequent error i met.
I took the bad habit to make only global variable as i had often need of them in different process, but if it take only few kb
I wil try to better think "local" process when no interconnect.

it took me a while to undesrand what happened within blocs. I think started to catch when dealing with some mouse down arrays of some usine items, just to be sure ive well understood:

I first did:
A)////////////////////////////////////////////////
for i:= 0 to l-1 do begin
if getDataArrayValue(ArrayIN,i)=1 then begin
setValue(msdwn,1);
end else begin
setvalue(msdwn,0);
end;
end;
B)///////////////////////////////////////////////////////////////////
tot:= 0;
for i:= 0 to l-1 do begin
tot:= tot + getDataArrayValue(ArrayIN,i);
if getDataArrayValue(ArrayIN,i)=1 then begin
setValue(msdwn,1);
end
else if tot:= 0 then begin
setValue(msdwn,0);
end;
end;
///////////////////////////////////////////////////////////////////////////////
if well remember, A was leading to pbs, cause within a bloc it would set msdwn to 1, but then to 0 if next element is 0, so
the parameter result bloc anyway would be 0, is that an exemple of the situation it if i well understood?
so is the B) tot method the best for such msdwn array?

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

Unread post by bsork » 03 Jun 2010, 15:17

If I understand you correctly, you want to set msdown to 1 if at least one element in the array is 1? Especially if the array is large, you should exit the loop when/if you find one. A WHILE or REPEAT UNTIL loop is more suited for this than a FOR loop, but you can still use a FOR and jump out with BREAK:

Code: Select all

VAR i, msVal &#58; Integer;
msVal &#58;= 0;
FOR i &#58;= 0 TO &#40;L - 1&#41; DO BEGIN
   IF &#40;GetDataArrayValue, ArrayIN, i&#41; = 1&#41; THEN BEGIN
      msVal &#58;= 1;
     BREAK;
   END;
END;
SetValue&#40;msdwn, msVal&#41;;
PS You got me a bit confused there - I thought the lower case L was and upper case I. How could that work?!?
Bjørn S

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 10 Jun 2010, 23:18

sorry i missed your post bsok thanks .yup i make too much complete loops, need to checks those others ways.
o yup Ll iI ooops

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests