<br>
Hi, Stephen!<br><br><div class="gmail_quote">2008/11/22 Stephen Sugden <span dir="ltr"><<a href="mailto:glurgle@gmail.com">glurgle@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Is it possible to mix both types of array keys?</blockquote><div><br><br>Yes... or at least it *should* be.... ;¬)<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The code I below works fine until I try to access any elements of the array, then I get an ArrayOutofBounds exception. </blockquote><div><br>I corrected the lack of a type for "melodies".<br><br>Then I had a hard time with it, as it turns out that this;<br>
<br>[ 0, 2, 4, 5, 7, 9, 11, 12 ] @=> int melodies[0];<br><br>crashes ChucK. That's a bug, and it's good that we accidentally found it but kindly try to avoid such confusion by making sure the code you send works as you described.<br>
<br>Right, on to the business at hand;<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br><<< scales["just"][0] >>>;<br>
<br></blockquote></div><br>You can't print the contents of a array (which this refers to) in one swoop like this, I fear. If you'd like to do this you'd have to loop over the array, if they all need to be on the same line and the length of the array is dynamic I think you'll have to join all elements together in a string and print that.<br>
<br>Let's look at a version that should work properly;<br><br>//===========================<br>float scales[0][0][0];<br><br>[ 0, 2, 4, 5, 7, 9, 11, 12 ] @=> int melodies[];<br><br>[ [1.0, 1.0], [16.0, 15.0], [9.0, 8.0], [6.0, 5.0], [5.0, 4.0],<br>
[4.0, 3.0], [7.0,5.0], [3.0, 2.0], [8.0,5.0], [5.0, 3.0],<br> [7.0, 4.0], [15.0, 8.0], [2.0, 1.0]<br>] @=> scales["just"];<br><br><br>float et[13][2];<br>for(0 => int i; i <= 12; ++i){<br> 1.0 => et[i][0];<br>
Math.pow(2.0, i / 12.0) => et[i][1];<br>}<br><br>et @=> scales["equalTempered"];<br><br>for(int n; n< scales["just"][0].cap(); n++)<br> {<br> //goes out of bound for n==0 already<br> <<<scales["just"][0][n]>>>;<br>
}<br>//==================<br><br>So... that's a bug, yes, and clearing out the associative indexes in favour of ints makes it go away. Good catch! <br><br>If you'd like; add it to the Wiki here; <a href="http://wiki.cs.princeton.edu/index.php/ChucK/Bugs/Release">http://wiki.cs.princeton.edu/index.php/ChucK/Bugs/Release</a><br>
<br>Yours,<br>Kas.<br>