Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
Your code does not account for situations where a key is held down for longer than one "tick".
You expect to be tapping the keys quickly without holding them down. But when the simulation speed is cranked up to the highest, you sometimes are unable to release the key quickly enough.
You can test this by holding down each key for a longer time instead of just tapping quickly --
even on slower simulation speeds, you will get consistently get the high pitch noise if you hold the key down long enough.
Long explanation:
The N4PB-8000 is non-blocking, i.e. similar to the radio chip. It produces three types of outputs:
[button] when the corresponding key is pressed
-[button] when the corresponding key is released
-999 if neither of the above
To gain a better understanding of how the part works, I suggest you create the following setup and watch the memory cells as you press, hold, and release buttons.
http://steamcommunity.com/sharedfiles/filedetails/?id=1266384854
Notice that if you hold down a key for a longer time instead of tapping quickly, you can get "-999" values in between the button-down and button-up values. This is the root of your problem.
You can even press a different key while holding the first one down! Try it and see what happens.
Currently, you expect your code to do this:
But what happens when a key is held down (or the simulation speed is high, and you don't manage to release the key fast enough), the following happens:
The easy solution to this would be to use the value from the button-down to trigger the FM blaster, and just ignore the negative button-up values along with the "no-event" -999s.
A more interesting thing you could do is to play the sound when the button is pressed, and stop the sound when the button is released. (This one has a potential pitfall you'll need to handle: if a second key is pressed while the first one is still being held down, you'll probably want to stop the first note and play the second one instead. Then, you should ignore the button-up for the first key, and only stop the second note when the second key is released.)
Thank you for taking a moment to point out where I was going wrong here. I probably would have spent a while trying to debug this today before I'd realize what was wrong.