This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Oni's profile picture

noteblock issue

Started by Oni, 16 April 2012 - 09:08 PM
Oni #1
Posted 16 April 2012 - 11:08 PM
Hello, i'm having an issue with noteblocks.
I have a couple of noteblocks put to a computer with bundled wire.
My problem is that when i'm playing the same note twice (rs.setBundledOutput("back", colors.orange) for example) it only plays the note the first time, and not the second time. I can play the note again once another note is played. what can i do to play the note twice without playing another note in between?

Thank you in advance.
MysticT #2
Posted 16 April 2012 - 11:22 PM
Without the code it's hard to find the problem, but I think it might be that you are not setting the output to 0 (no colors) after playing a note. You should use pulses (on, wait, off) to play the notes.
Oni #3
Posted 16 April 2012 - 11:56 PM
I'm having a series of notes played. It's not the best way to do it, i guess. But it's the only way to think of.

It starts with :

rs.setBundledOutput("back", colors.lightGray)
sleep(0.2)
rs.setBundledOutput("back", colors.lightBlue)
sleep(0)
rs.setBundledOutput("back", colors.gray)
sleep(0)
rs.setBundledOutput("back", colors.orange)
sleep(0.2)
rs.setBundledOutput("back", colors.gray)
sleep(0.2)
rs.setBundledOutput("back", colors.orange)
sleep(0.2)
rs.setBundledOutput("back", colors.lightGray)
sleep(0.2)
rs.setBundledOutput("back", colors.lightGray)
with in the ending playing the last note only once. It's basicly one computer hooked up to a series of noteblocks, to play a song of sorts.
MysticT #4
Posted 17 April 2012 - 12:04 AM
The problem is what I said, you are not turning the output off after playing a note. Noteblocks play the note when they receive a redstone signal (when the cable turns on), so the cable must be off before playing the note (it's off, you turn it on, it plays the note).
This is a function that I used when doing something similar:

function Pulse(sSide, nColors)
  rs.setBundledOutput(sSide, nColors)
  sleep(0.2)
  rs.setBundledOutput(sSide, 0)
end
You can use it to play the notes like this:

Pulse("back", colors.lightGray)
Pulse("back", colors.lightBlue)
...
Pulse("back", colors.lightGray)
Pulse("back", colors.lightGray)
Oni #5
Posted 17 April 2012 - 05:31 PM
Ah, i see. Thank you very much. My understanding of lua is not very big, but I'm learning.
Also, i'm sorry for asking. But would it also be possible to change the function in such a way that the side of the signal will be predetermined, so that i would not have to write that every time?

And sorry for the late reply, i fell asleep soon after.
MysticT #6
Posted 17 April 2012 - 06:22 PM
Yes, it's possible and very easy, just remove the side parameter and put the side on the functions:

function Pulse(nColors)
  rs.setBundledOutput("side", nColors) -- change side to the side you want
  sleep(0.2)
  rs.setBundledOutput("side", 0) -- again, change the side
end
You could also define a variable to store the side:

local sSide = "back" -- change to the side you want

function Pulse(nColors)
  rs.setBundledOutput(sSide, nColors)
  sleep(0.2)
  rs.setBundledOutput(sSide, 0)
end
This way you can set that variable to the side you want, send some pulses on that side, change to another side and repeat:

sSide = "back"
Pulse(colors.blue)
Pulse(colors.red)
sSide = "left"
Pulse(colors.black)
Oni #7
Posted 17 April 2012 - 06:52 PM
Hmm, i see. Thank you a lot for your help.
Hawk777 #8
Posted 19 April 2012 - 07:46 AM
Don't you need a second sleep in that function? Otherwise this code:

Pulse(colors.black)
Pulse(colors.black)

would effectively expand to this:

rs.setBundledOutput("back", colors.black)
sleep(0.2)
rs.setBundledOutput("back", 0)
rs.setBundledOutput("back", colors.black)
sleep(0.2)
rs.setBundledOutput("back", 0)

which I don't think will actually ever turn the wire off, because it doesn't wait at all before turning it back on?
MysticT #9
Posted 19 April 2012 - 06:05 PM
Hmm, seems that I missed a line. I had it working in my code, and was able to play any note on any instrument, but I deleted the world it was on and lost everything :)/>/>
It should be like this:

function Pulse(nColors)
  rs.setBundledOutput("side", nColors)
  sleep(0.2)
  rs.setBundledOutput("side", nColors)
  sleep(0.2)
end