TristanTroll, on 06 September 2012 - 11:32 PM, said:
So would that go on top of this or what?
local function bellTimer()
sleep(3600)
end
while true do
parallel.waitForAll(bellTimer, playbell)
end
My turn again lol
Ok, so let's say you've got all your noteblocks set up at the back of your computer, hooked up to a bundled cable.
You know you want to play, and how you are going to play it (eg the order of noteblocks).
Then you figure out the code required to play the song, which may look something like this:
local side = "back"
redstone.setBundledOutput(side, colours.blue)
sleep(0.15)
redstone.setBundledOutput(side, colours.green)
sleep(0.1)
redstone.setBundledOutput(side, colours.red)
sleep(0.15)
redstone.setBundledOutput(side, colours.green)
sleep(0.1)
redstone.setBundledOutput(side, colours.blue)
sleep(0.3)
redstone.setBundledOutput(side, colours.red)
sleep(0.2)
Now you want to put this in a function, which would be achieved like so:
local function playsong()
local side = "back"
redstone.setBundledOutput(side, colours.blue)
sleep(0.15)
redstone.setBundledOutput(side, colours.green)
sleep(0.1)
redstone.setBundledOutput(side, colours.red)
sleep(0.15)
redstone.setBundledOutput(side, colours.green)
sleep(0.1)
redstone.setBundledOutput(side, colours.blue)
sleep(0.3)
redstone.setBundledOutput(side, colours.red)
sleep(0.2)
end
Since this function is only performing a song, you don't need to worry about it giving back any data with the 'return' statement, the only bit you need to worry about now is the fact that by putting this block of code in a function, it can be called on as required.
To call this function, simply use the line
playsong()
Anywhere after the function is declared. (Some languages are different, but in lua a function has to be declared before you call it because of the way the code is read/compiled.)
Now for the actual code of the program (assuming you have already declared the playsong function at the top of your program):
while true do
playsong()
sleep(3600)
end
This will play your song and then sleep the console for an hour. Don't forget to account for how long your song plays for.
Eg time how long it takes to play and subtract that amount from the sleep time. So, if it takes 12 seconds, change sleep(3600) to sleep(3588).
That's assuming you want to make it chime on every real world hour. Minecraft time is something rather different, but can also be done with the right arrangement. I could have done this using the parallel API, but that would require explaining the basic ideas of the parallel API. I can do this if you want, since it will save you attempting to time your song, but it would still take a bit more time to explain.