[chuck-users] how do you maipulate an array with rand2()?
Spencer Salazar
ssalazar at CS.Princeton.EDU
Tue Nov 14 00:50:19 EST 2006
Hi Malik,
Welcome to ChucK land!
What you have found is a bug, the lack of a feature, or a result of
strong typing (depending on your point of view), in which the type of
the first element of an array determines the overall type of an
array. This is better explained by example:
[ 0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75, 1166.375 ] @=>
float push[];
produces an error, whereas
[ 0.0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75, 1166.375 ]
@=> float push[];
does not produce an error (but is functionally equivalent). The
difference is that the first element is explicitly a float when
initializing the array of floats. hopefully this clarifies things a
bit.
spencer
On Nov 13, 2006, at 10:21 PM, Malik Martin wrote:
> hi i already posted this on the forums, but it doesnt seem as
> active as
> i imagine the mailing list might be(no offense of course).
>
> so here's my post
>
> hi
> i'm trying to access an array with rand2() but i get syntax errors:
>
> while( true )
> {
> //1 bar at 180bpm cut into 8ths
> float push[ 0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75,
> 1166.375 ]
> push[Math.rand2(0,7)] => buf.pos;
>
> 1333::ms => now;
> }
>
> i made a second post with a minor update
>
> i noticed my syntax errors in comparison to otf_06.ck on page 49 in
> the
> manual and re-wrote it.
>
> // time loop
> while( true )
> {
> //1 bar at 180bpm cut into 8ths
> [ 0, 166.625, 333.25, 499.875, 666.5, 833.125, 999.75, 1166.375 ]
> @=>
> float push[];
> push[Math.rand2(0,7)] => buf.pos;
>
> 1333::ms => now;
> }
>
> but i still get this error: [SndBufTest1.ck]:line(19): array init
> [...]
> contains incompatible types...
>
> Malik
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
More information about the chuck-users
mailing list