Speaker wont wait and plays sound endlessly

Started by Dewrot, May 11, 2021, 06:53 AM

Previous topic - Next topic

Dewrot

I am trying to make an alarm button to base my other creations on. It has many elements that I can use as an example for my other projects...but my alarm wont function properly... It is supposed to play a sound and wait 1.05 seconds and then play it again... but it plays a new one every tick instead. I cant wrap my head around it...Ive tried sleep and alarms. What do I do?!

Modpack: All of Fabric 3

Code: https://pastebin.com/z416SvAR

Needed: Advanced Monitor
        Speaker

Monitor needs to be on top and the speaker can be anywhere.

Lupus590

You are not using the timer event, I would look at how the sleep function works.

Also, speaker.playSound has no idea how long the sound is and returns instantly, so you keep playing the sound every time you pull an event.

Dewrot

I think one of my main issues is that I dont fully understand what I am trying to write.
Im very new to LUA (havent written CC code in YEARS), and I'm being too ambitious. I figured out that when I use sleep the program becomes unresponsive to input and and the alarm event simply doesnt work the way i thought.

Im looking over timer events and without a good example Im still a little baffled. Dont write my code for me... but perhaps an example that could help? I learn from example and I havent found anything too terribly helpful... I know i am close but not quite there.

Dewrot

OMG I figured out a solution! Im going to polish it up a bit and reupload... Im still having an issue with my character quit event being buggy. It requires me to press it twice and if I press it once I have to do any other input twice.