11 posts
Posted 24 April 2012 - 07:44 PM
so ive made this recently, and i wanted to make some music with it like in this video: [media]
http://www.youtube.com/watch?v=1Z3B1caaNWA[/media]
but the thing is…. i dont get how this person programs it, ive asked him but he hasnt replied. do i litteraly have to sit there and redstone output true sleep then false for every damn color and note? that would take years.
basicly, im asking the most efficient way to make music with this possible in craftOS1.3
thanks!
474 posts
Posted 24 April 2012 - 08:09 PM
Try this:
local amount = 5 -- CHANGE 5 TO HOW MANY TIMES YOU WANT IT TO LOOP CODE
for DoNotChangeThis=1,amount do
--code
end
That code will loop the code inside of the for loop (the –code) 5 times. Change 'amount' to how many times you want to loop it.
436 posts
Posted 24 April 2012 - 09:14 PM
Hmm. To help a bit further, you can also do c.combine(), and put each of the notes in that way, which will reduce the amount of lines you will have.
And, he is loading from a floppy, which probably has a file with the notes already on it. The program just needs to load it and place the notes in a table, and then read off each line in a rs.setBundledOutput(). That requires a little math, though.
161 posts
Posted 25 April 2012 - 03:16 AM
The fundamental rule of doing something like this: separate data and code! The operation of actually playing a note is code (given a particular note to play and a particular interval of time before the next note, turn on the appropriate redstone output, wait a bit, turn the redstone output off, wait a bit more, up to the total delay). The list of notes and times to play is data. Keep those separate and you keep things simple. There are a number of ways you could do that. Most simply, you could encapsulate playing of a note into a function and then just list out a pile of calls to the function to make up the music; that would reduce you to one line of code per note which is fairly reasonable. You could go further and put the notes in an external file and have your program read the file and play the notes; this way you would design the language of the file containing the notes (so you could make it really concise to save yourself lots of typing), and on the side you'd be able to let the user run the program and specify a file of their choice, so they could play various different songs.