First time here? Check out the FAQ!
x

indexable collection of arrays

0 votes
431 views
hello dear Kyma friends,

I would like to have find a way to store a collection of different arrays and to select at runtime which one I need for my sound.

I am trying with this script on a STGC:

1 to: 8 do: [:i |
    stgc start: 0 s
    pt: (!Script of: #( {#(1 0 1 0 1 0 1 0)} {#( 2 5 2 5 3 4 34)})) at: i
    debug: ('debug'&i) asHotValue]

but I get this error message:

"Error: The message #*, sent to (1 0 1 0 1 0 1 0), an instance of class Array, was not understood"

I got this message also in other sound and script that I have been trying for this purpose.

thanks.

d
asked May 6, 2019 in Capytalk & Smalltalk by domenico-cipriani (Master) (3,110 points)

2 Answers

+1 vote
 
Best answer

Re-reading your question, I see that you wanted eight STGCs! So instead, you could use:

1 to: 8 do: [:i |
    stgc start: 0 s 
    pt: (!Script of: (#( #(1 0 1 0 1 0 1 0) #( 2 5 2 5 3 4 34) ) collect: [ :array | array at: i]))
    debug: ('debug'&i) asHotValue]

In this example, !Script selects an element within the array that consists of a collection of values taken from the i-th entry of each of your arrays.

(I left the other answer too, just in case someone else would prefer to use that approach).

answered May 7, 2019 by ssc (Savant) (128,000 points)
selected May 7, 2019 by domenico-cipriani
thanks a lot!
this is what I needed :)

I have another question regarding this:
when should array be put inside curlies?
and if I would like to declare a variable containing one of the arrays;
for example
|p1|
p1 := #(1 0 1 0 1 0 1 0).

where should it be placed?
0 votes

Hello Domenico,

I think the issue is that the Smalltalk message at: is computed at compile-time, not at run-time. If instead you use the Capytalk of:, for example,

(!Index_i of: #(0 1 2)) of: #({!Index_j of: #(10 11 12)} {!Index_j of: #(20 21 22)} {!Index_j of: #(30 31 32)})

then !Index_i will select one of the Arrays: #(10 11 12)  #(20 21 22) #(30 31 32). And !Index_j will select one element from that Array.

For example, for !Index_1 = 1 and !Index_j = 2, the value of the expression is 22.

Whereas, for !Index_1 = 2 and !Index_j = 0, the value of the expression is 30.

answered May 7, 2019 by ssc (Savant) (128,000 points)
...