I actually wasn't aware of the length operator, so thanks again Dromiceius, you're very helpful as always. :)
With this information, I now present my "Pi music script" - run this script on the "NES Test cart" ROM when in the controller test mode - it will play up the decimals of pi, with each decimal corresponding to a joypad input - you can change the value of the variable "length" to vary how many frames the notes will play. Because there are 10 digits but only 8 buttons, I assigned digits 0 and 9 to controller 2. So if you have ever wondered what pi sounds like in music format, you can now find out:
pi ={[0]
=1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5,0,2,8,8,4,1,9,
7,1,6,9,3,9,9,3,7,5,1,0,5,8,2,0,9,7,4,9,4,4,5,9,2,3,0,7,8,1,6,4,0,6,2,8,6,2,0,
8,9,9,8,6,2,8,0,3,4,8,2,5,3,4,2,1,1,7,0,6,7,9,8,2,1,4,8,0,8,6,5,1,3,2,8,2,3,0,
6,6,4,7,0,9,3,8,4,4,6,0,9,5,5,0,5,8,2,2,3,1,7,2,5,3,5,9,4,0,8,1,2,8,4,8,1,1,1,
7,4,5,0,2,8,4,1,0,2,7,0,1,9,3,8,5,2,1,1,0,5,5,5,9,6,4,4,6,2,2,9,4,8,9,5,4,9,3,
0,3,8,1,9,6,4,4,2,8,8,1,0,9,7,5,6,6,5,9,3,3,4,4,6,1,2,8,4,7,5,6,4,8,2,3,3,7,8,
6,7,8,3,1,6,5,2,7,1,2,0,1,9,0,9,1,4,5,6,4,8,5,6,6,9,2,3,4,6,0,3,4,8,6,1,0,4,5,
4,3,2,6,6,4,8,2,1,3,3,9,3,6,0,7,2,6,0,2,4,9,1,4,1,2,7,3,7,2,4,5,8,7,0,0,6,6,0,
6,3,1,5,5,8,8,1,7,4,8,8,1,5,2,0,9,2,0,9,6,2,8,2,9,2,5,4,0,9,1,7,1,5,3,6,4,3,6,
7,8,9,2,5,9,0,3,6,0,0,1,1,3,3,0,5,3,0,5,4,8,8,2,0,4,6,6}
m=pi
n=0
length=12
c=length
d="3."
while n<=#m do
key1={}
key2={}
u=m[n]
if c==0 then n=n+1 c=length d= d .. u end
c=c-1
if u==1 then key1.A=1 end
if u==2 then key1.B=1 end
if u==3 then key1.start=1 end
if u==4 then key1.select=1 end
if u==5 then key1.left=1 end
if u==6 then key1.up=1 end
if u==7 then key1.right=1 end
if u==8 then key1.down=1 end
if u==9 then key2.A=1 end
if u==0 then key2.B=1 end
joypad.set(1,key1)
joypad.set(2,key2)
gui.text(10,18,"Tone length: " .. length)
gui.text(10,26,"Number: " .. d)
FCEU.frameadvance()
end