muddling up an array
- nay-seven
- Site Admin
- Posts: 5684
- Location: rennes France
- Contact:
A job for a script guru...?
-
caco
- Member
- Posts: 306
Here is a quick one off the top of my head, not tested or optimized either so let me know if it doesn't work! If you need it to be more efficient I can come up with something much better using the C++ SDK as I am still unfamiliar with the script's Pascal syntax 
Code: Select all
var ArrayIn, ButtonIn, ArrayOut : tparameter;
///////////////////////////////////////////////
procedure init;
begin
ArrayIn:= CreateParam('Array in',ptarray); SetisOutput(ArrayIn,false);
ButtonIn:= CreateParam('Shuffle',ptbutton); SetisOutput(ButtonIn,false);
Arrayout:= CreateParam('Arrayout',ptarray); Setisinput(ArrayOut,false);
end;
//////////////////////////////////////
Procedure Callback(N:integer);
Var i, j : Integer;
Var temp : real;
begin
if (N=ButtonIn) then begin
for i:= 0 to GetLength(ArrayIn)-1 do begin
SetDataArrayValue(ArrayOut, i, GetDataArrayValue(ArrayIn, i));
end;
SetLength(ArrayOut, GetLength(ArrayIn));
for i:= GetLength(ArrayOut)-1 downto 0 do begin
j := random(i);
temp := GetDataArrayValue(ArrayOut, j);
SetDataArrayValue(ArrayOut, j, GetDataArrayValue(ArrayOut, i));
SetDataArrayValue(ArrayOut, i, temp);
end;
end;
end;- nay-seven
- Site Admin
- Posts: 5684
- Location: rennes France
- Contact:
works fine Caco, but only for array with min=0, max=100
if not you have to set those values manually
if not you have to set those values manually
- nay-seven
- Site Admin
- Posts: 5684
- Location: rennes France
- Contact:
yes, but i just realize that modules like swap or shift array don't get (and set) those values automatically , so maybe it's normal ..?
-
caco
- Member
- Posts: 306
Is this any better? Seems to work fine here now.
Code: Select all
var ArrayIn, ButtonIn, ArrayOut : tparameter;
///////////////////////////////////////////////
procedure init;
begin
ArrayIn:= CreateParam('Array in',ptarray); SetisOutput(ArrayIn,false);
ButtonIn:= CreateParam('Shuffle',ptbutton); SetisOutput(ButtonIn,false);
Arrayout:= CreateParam('Arrayout',ptarray); Setisinput(ArrayOut,false);
SetMin (ArrayIn, 1.4e-45); // set min parameter value
SetMax (ArrayIn, 3.4e38); // set max parameter value
SetMin (ArrayOut, 1.4e-45); // set min parameter value
SetMax (ArrayOut, 3.4e38); // set max parameter value
end;
//////////////////////////////////////
Procedure Callback(N:integer);
Var i, j : Integer;
Var temp : real;
begin
if (N=ButtonIn) then begin
for i:= 0 to GetLength(ArrayIn)-1 do begin
SetDataArrayValue(ArrayOut, i, GetDataArrayValue(ArrayIn, i));
end;
SetLength(ArrayOut, GetLength(ArrayIn));
for i:= GetLength(ArrayOut)-1 downto 0 do begin
j := random(i);
temp := GetDataArrayValue(ArrayOut, j);
SetDataArrayValue(ArrayOut, j, GetDataArrayValue(ArrayOut, i));
SetDataArrayValue(ArrayOut, i, temp);
end;
end;
end;- nay-seven
- Site Admin
- Posts: 5684
- Location: rennes France
- Contact:
it works if you create the 2 array from the script , but i mean if you have a project with an array with min =20 and max =80 , and you want add your script behind this one, this don't work..?
i suppose we need here 2 variable , min and max and get their value from the first array..?
but it's not a big deal , so don't waste time for this if you don't have..
i suppose we need here 2 variable , min and max and get their value from the first array..?
but it's not a big deal , so don't waste time for this if you don't have..
-
caco
- Member
- Posts: 306
Yes, but this is the same with all array modules that you need to make sure second array is compatible with first array for min, max etc I think?
Made minor change so that Array Out is now saved in patch as was not being restored before.
Made minor change so that Array Out is now saved in patch as was not being restored before.
Code: Select all
//////////////////////////////////////////////
// Randomly reorders data in array
// Version 1.01
// 2 July 2012
// By Caco
//////////////////////////////////////////////
var ArrayIn, ButtonIn, ArrayOut : tparameter;
///////////////////////////////////////////////
procedure init;
begin
ArrayIn:= CreateParam('Array in',ptarray); SetisOutput(ArrayIn,false);
ButtonIn:= CreateParam('Shuffle',ptbutton); SetisOutput(ButtonIn,false);
Arrayout:= CreateParam('Array out',ptarray); Setisinput(ArrayOut,false);
SetMin (ArrayIn, 1.4e-45); // set min parameter value
SetMax (ArrayIn, 3.4e38); // set max parameter value
SetMin (ArrayOut, 1.4e-45); // set min parameter value
SetMax (ArrayOut, 3.4e38); // set max parameter value
SetDontSave (ArrayOut, FALSE);
end;
//////////////////////////////////////
Procedure Callback(N:integer);
Var i, j : Integer;
Var temp : real;
begin
if (N=ButtonIn) then begin
for i:= 0 to GetLength(ArrayIn)-1 do begin
SetDataArrayValue(ArrayOut, i, GetDataArrayValue(ArrayIn, i));
end;
SetLength(ArrayOut, GetLength(ArrayIn));
for i:= GetLength(ArrayOut)-1 downto 0 do begin
j := random(i);
temp := GetDataArrayValue(ArrayOut, j);
SetDataArrayValue(ArrayOut, j, GetDataArrayValue(ArrayOut, i));
SetDataArrayValue(ArrayOut, i, temp);
end;
end;
end;- nay-seven
- Site Admin
- Posts: 5684
- Location: rennes France
- Contact:
yes, you're certainly right, i sadly don't have time to study scripts right now, i first thing we can use something like GetDataArrayValue and a variable to get the min & max then set them back
or a GetMin equivalent to the GetLength we have yet
definitively need a parallel life...
or a GetMin equivalent to the GetLength we have yet
definitively need a parallel life...
