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

[solved]os.startTimer and my Iron Note Block Player.

Started by Left4Cake, 20 February 2013 - 11:52 AM
Left4Cake #1
Posted 20 February 2013 - 12:52 PM
I am having issues with os.startTimer in http://www.computerc...player-cctunes/

I put timer = os.startTimer(song["delay"]) befor ​while i * song["delay"] < song["lenght"] + 1 do right after

file = io.open( "Music/" .. selectedsong )
filedata = file:read()
file:close()
and after while i * song["delay"] < song["lenght"] + 1 do replacing

os.sleep(song["delay"])

but when I use it the song seems to keep increasing in speed after each key press, until is give me an error for more then 5 notes per tick on a single block. :(/>
nLgzHungryHiPPo #2
Posted 20 February 2013 - 03:08 PM
well, for starters your string is lenght instead of length. That wouldn't matter as long as you're misspelling it in all locations though.
Left4Cake #3
Posted 20 February 2013 - 03:25 PM
well, for starters your string is lenght instead of length. That wouldn't matter as long as you're misspelling it in all locations though.

lol, nothing a simple "replace all" can't fix.

Anyway I did figure it out. For anyone else searching for a simmiler anwser.


os.startTimer(song["delay"])
evt, arg1, arg2 = os.pullEvent()

if evt ~= "timer" then
	 os.sleep(song["delay"])
end

My problem was that for the music to be consistent I always need the either a os.sleep(song["delay"]) or os.startTimer(song["delay"]), however when someone pushes a key that ends the timer. So I need os.sleep to pick up the slack when os.startTimer is not present, of course its not perfect if some one is raptly pushing buttons or the song is really slow, there is a noticeable delay, but for normal use this works.
immibis #4
Posted 20 February 2013 - 04:43 PM
It actually doesn't end the timer. You will still get the "timer" event when the time is up.

You're also not checking which timer the event is for, so if any timer expires then you play the note.


timerID = os.startTimer(song["delay"])

Now arg1 == timerID when the timer event is for that timer.