I think I solved the riddle using a prefix for the json identifier that I concat as a global String var at k rate with the actual identifier name for storing changes. In the example I initialise the prefix as “init_” and then I change it to “perform_” in an instrument that gets called with a bit of a delay. The first k-cycle parses the initialised empty array to the identifier with the “init_” prefix and the stored data under the identifier with the “perform_” prefix stays intact. Did it only for Slider2 while Slider1 has the old solution, that doesn’t work anymore.
gkslider1Array[] init 10
gkslider2Array[] init 10
gSprefix init "init_"
instr 1
kNumber init 0
kNumber = (changed(chnget:k("next")) == 1 && kNumber < 9)? kNumber + 1 : kNumber // change active index
kNumber = (changed(chnget:k("prev")) == 1 && kNumber > 0)? kNumber - 1 : kNumber // with buttons
if( changed(kNumber) == 1 ) then
String sprintfk "text(\"%d\")",kNumber // index
cabbageSet 1, "number", String
cabbageSetValue "slider1",gkslider1Array[kNumber]
cabbageSetValue "slider2",gkslider2Array[kNumber]
endif
strset 1,"dummy"
kslider1 chnget "slider1"
if(changed(kslider1) == 1)then
gkslider1Array[kNumber] = kslider1
SIdent sprintfk "%s", "dataSlider1"
SIdent strget 1
cabbageSetStateValue SIdent, gkslider1Array
endif
kslider2, ktrig2 cabbageGetValue "slider2"
if(changed(kslider2) == 1)then
gkslider2Array[kNumber] = kslider2
SIdent sprintfk "%s_dataSlider2",gSprefix
cabbageSetStateValue SIdent, gkslider2Array
endif
if( changed(chnget:k("print")) == 1) then // call instrument to print the stored data
event "i","printStoredData",0,0
endif
endin
instr printStoredData
prints "\n\nPrinting using readStateData\n"
prints cabbageReadStateData:S()
endin
instr enablePrefix
gSprefix sprintfk "%s","perform_"
endin
and then in the score:
i 1 0 z
i "enablePrefix" 0.1 0.0008
Seems to be working with your current version.
And it’s even shorter than the old solution.