# Sending ARRAY info from one script slot to another



## jdawg (May 13, 2014)

Hi, 
im trying to send the contents of an array from one script slot to another. 

tried the following, but its not working, any tips collective mind of the scripting world?

GETTING THE INFORMATION


> on ui_control(%TABLE)
> $i := 0
> while ($i <= 32)
> %TABLE_CALLBACK[$i]:= %TABLE[$i]
> ...



RECEIVING THE INFORMATION


> on pgs_changed
> 
> if (pgs_key_exists(TABLE) and pgs_get_key_val(TABLE,0) = 1)
> $i := 0
> ...


----------



## mk282 (May 13, 2014)

In Kontakt 5 there are string PGS variables that help with that...


----------



## Aviram Dayan Production (Jun 28, 2018)

this post is very old ..
but I'm stuck with the same issue,
there is a little example from pgs table? that works
because i tried different ways, and also with "while" loop
with no success
tnx


----------



## Tod (Jul 2, 2018)

I did this a while back, take a look at it and it might help. The top bit of code is the sending slot. There's a more code in the sending and receiving slots but I'd have to track it down so I hope this helps.

Since this thread is about sending arrays from one slot to another, pay attention to the "for loops".

Also there might be a better way to do this and somebody might chime in, but this works very well for me, it's for sending keymaps from one slot to another.


```
{the sending script slot}
on pgs_changed
  if(pgs_key_exists(EVNT_NOTE))
    $EvntNote := pgs_get_key_val(EVNT_NOTE,0)
  end if
  if ($FirstTime = 1)
    pgs_set_key_val(RESET_DRUMS, 0, 0)
    for $cnt1 := 0 to Last_Kit_Pc
      pgs_set_key_val(IDX_NUM, 0, $cnt1)
      pgs_set_key_val(PLAY_KEY, 0, %New_Key [$cnt1])
      wait(1000)
    end for
    $FirstTime := 0
  end if
end on
on note

{the receiving script slot}
on pgs_changed
  if(pgs_key_exists(IDX_NUM) and pgs_key_exists(PLAY_KEY))
    $Org_Idx := pgs_get_key_val(IDX_NUM,0)
    $cnt1 := pgs_get_key_val(IDX_NUM,0)
    $cnt2 := pgs_get_key_val(PLAY_KEY,0)
    %Keys [$cnt1] := $cnt2
  end if
  if (pgs_key_exists(RESET_DRUMS))
    if (pgs_get_key_val(RESET_DRUMS,0) = 1)
      for $cn := 0 to $LAST_KIT_PC
        %Keys[$cn] := %Org_Key[$cn]
      end for
    end if
    if (pgs_get_key_val(RESET_DRUMS,0) = 2)
      for $cn := 0 to $LAST_KIT_PC
        %Keys[$cn] := -1
      end for
    end if
  end if
  if (pgs_key_exists(STOP_PLAY))
    $Do_Not_Play := pgs_get_key_val(STOP_PLAY,0)
  end if
end on
```


----------



## Aviram Dayan Production (Jul 2, 2018)

Tod said:


> I did this a while back, take a look at it and it might help. The top bit of code is the sending slot. There's a more code in the sending and receiving slots but I'd have to track it down so I hope this helps.
> 
> Since this thread is about sending arrays from one slot to another, pay attention to the "for loops".
> 
> ...



Hello Tod, thanks for your reply
but it's not really good for me.

i need simple %table [128] ,
any size that are pressed, will be sync with the second table & slot



```
on init
make_perfview
set_ui_height_px(200)

declare $variable_loop

declare ui_table %Table [128] (3,3,-50)
move_control_px(%Table,3,60)
%Table[$variable_loop] := 0
set_control_par(get_ui_id(%Table),$CONTROL_PAR_BAR_COLOR,16101170)
set_control_par(get_ui_id(%Table),$CONTROL_PAR_WIDTH,625)
set_control_par(get_ui_id(%Table),$CONTROL_PAR_HEIGHT,36)
set_control_par_str(get_ui_id(%Table),$CONTROL_PAR_HELP,"Tabl")
make_persistent(%Table)
read_persistent_var(%Table)
{pgs}
pgs_create_key(TABLE,128)
end on


on pgs_changed

%Table[128] := pgs_get_key_val (TABLE, $variable_loop)

{don't work}
{
$variable_loop := 0
while ($variable_loop < 128)
%Table[$variable_loop] := pgs_get_key_val (TABLE, $variable_loop)
inc($variable_loop)
end while
}
end on


on ui_control(%Table)
pgs_set_key_val(TABLE,0 {or $variable_loop},%Table[128])
end on
```


----------



## polypx (Jul 3, 2018)

if you only need the array to be size 128, you can simply use a PGS Key with 128 values. It will always be in sync automatically.


----------



## EvilDragon (Jul 3, 2018)

PGS keys aren't persistent so it wouldn't survive reloading the NKI, IIRC?


----------



## Aviram Dayan Production (Jul 3, 2018)

EvilDragon said:


> PGS keys aren't persistent so it wouldn't survive reloading the NKI, IIRC?


amm.. you mean the second slot, cannot get such a big size of area
when is pressed at the same time on one table? (through while loop)
have you tried in the past?


----------



## EvilDragon (Jul 3, 2018)

Not sure what you're talking about at all. PGS keys can have up to 256 entries...


----------



## polypx (Jul 3, 2018)

EvilDragon said:


> PGS keys aren't persistent so it wouldn't survive reloading the NKI, IIRC?


Yes, but once that was saved/restored... you wouldn't need to pass anything via "on pgs changed"


----------



## Aviram Dayan Production (Jul 3, 2018)

polypx said:


> if you only need the array to be size 128, you can simply use a PGS Key with 128 values. It will always be in sync automatically.


128 values, it's just example



polypx said:


> Yes, but once that was saved/restored... you wouldn't need to pass anything via "on pgs changed"


if it is possible,
please put here a simple code example,
with PGS keys & table (through while loop)
tnx


----------



## polypx (Jul 3, 2018)

You could check the manual, it's in there. But here's a simple example:



```
on init
declare $i
declare %backup[128]
make_persistent(%backup)
pgs_create_key(ARRAY, 128)
end on

on persistence_changed
$i := 0
while ($i < 128)
pgs_set_key_val(ARRAY, $i,%backup[$i])
inc($i)
end while
end on

on pgs_changed
$i := 0
while ($i < 128)
%backup[$i] := pgs_get_key_val(ARRAY, $i)
inc($i)
end while
end on
```

This will save and recall the array in one slot, but you can access the array from any slot, or change it from any slot, using the pgs commands.


----------



## Aviram Dayan Production (Jul 3, 2018)

polypx said:


> You could check the manual, it's in there. But here's a simple example:
> 
> 
> 
> ...



tnx to you bro,
i missed the "while" loop in the "on ui_control" UI callback
and you missed the i$:=0 "on persistence_changed"
like that everything work correctly


```
on init
make_perfview
set_ui_height_px(200)

declare $variable_loop

declare ui_table %Table [128] (3,3,-50)
move_control_px(%Table,3,60)
%Table[$variable_loop] := 0
set_control_par(get_ui_id(%Table),$CONTROL_PAR_BAR_COLOR,16101170)
set_control_par(get_ui_id(%Table),$CONTROL_PAR_WIDTH,625)
set_control_par(get_ui_id(%Table),$CONTROL_PAR_HEIGHT,36)
set_control_par_str(get_ui_id(%Table),$CONTROL_PAR_HELP,"Tabl")
make_persistent(%Table)
read_persistent_var(%Table)
{pgs}
pgs_create_key(TABLE,128)

end on


on pgs_changed
$variable_loop := 0
while ($variable_loop < 128)
%Table[$variable_loop] := pgs_get_key_val(TABLE, $variable_loop)
inc($variable_loop)
end while
end on


on ui_control(%Table)
$variable_loop := 0
while ($variable_loop < 128)
pgs_set_key_val(TABLE, $variable_loop,%Table[$variable_loop])
inc($variable_loop)
end while
end on
```


and about "on persistence_changed" i'll add to my store later
First, it was important for me to control it


----------

