Help with a jukebox!
Post Reply
Quote
Re: Help with a jukebox!
Posted by DarkHand on Sun Aug 1st at 12:50am 2010


Hi all! Working on a Jukebox that plays a selection of random songs when toggled, and it's driving me nuts.

Ok, so I have a logic_case that randomly loops through a set of 7 songs. It doesn't need to be able to be turned off, but it needs to start off, and be able to be toggled on every multiplayer round. Here were my first outputs:

(EDIT: Hey, the code tag doesn't properly retain spacing smiley. Hope you can still follow.)
Code

Logic_Case

Name: SongChooser

| Output | Target Entity | Target Input | Delay |
| | | | |
| OnCase01 | Song1 | PlaySound | 0 |
| OnCase01 | SongChooser | PickRandom | 61 |
| OnCase02 | Song2 | PlaySound | 0 |
| OnCase02 | SongChooser | PickRandom | 73 |

And so on. The Song# entities are ambient_generics that play the songs, and the delays are the lengths of the songs. After a particular song has played, the entity calls itself and randomly plays another song, then waits the length of that song, and the cycle continues.

The problem is that on round restart, everything resets except the delay timers (at least that's how it's working in the mod I'm on, Hidden:Source). The music stops, but if you were, say, 30 seconds into a 61 second song, another song automatically plays 31 seconds into the next round, and keeps going after that. Toggling SongChooser in the new round then results in two songs playing at once.

After that, I came up with the idea of calling a sanity check func_button instead of directly calling the next song... If the button is locked, it can't play the next song and the chain breaks.

The button idea was a partial solution... Here's what I have now:

Code

Logic_Case

Name: SongChooser

| Output | Target Entity | Target Input | Delay |
| | | | |
| OnCase01 | Song1 | PlaySound | 0 |
| OnCase01 | SongChecker | Press | 61 |
| OnCase02 | Song2 | PlaySound | 0 |
| OnCase02 | SongChecker | Press | 73 |

-----------------------------------------------------------

Func_Button

Name: SongChecker
Flags: Start Locked

| Output | Target Entity | Target Input | Delay |
| | | | |
| OnPressed| SongChooser | PickRandom | 0 |

I changed the button that toggles SongChooser to first unlock SongChecker.

Now, even if the SongChooser delay is still ticking away, when it tries to press SongChecker, the button is locked if the round has restarted, breaking the chain! Fixed, right?

The problem now is that if you toggle SoundChooser back on too quickly, the chain hasn't had a chance to break yet, and you end up with the same problem since the timer is still counting down and you've already reopened SongChecker. Trying to come up with a way to get around that now.

Am I going about this in the completely wrong manner? Or am I missing some little thing that will fix it?

Any ideas?




Quote
Re: Help with a jukebox!
Posted by DarkHand on Mon Aug 2nd at 12:58am 2010


Accepted Answer
Solved it with help from Zeph on the UberMicro forums!

Instead of using output delays to control the timing, the solution is to use a logic_timer and RefireTime to change it's timing.

logic_timer output:
OnTimer -> SongChooser -> PickRandomShuffle

logic_case OnCase outputs:
OnCase01 -> "Song1" -> PlaySound
OnCase01 -> "LogicTimerName" -> RefireTime -> "61" (or whatever the length of the song is)

The jukebox 'start button' enables the logic_timer, which calls pickrandomshuffle on the logic_case that contains the 7 songs. The logic_case picks a song and plays it, and changes the refire time on the logic_timer to the length of that song. After that time (which is now the length of the song that's playing), the logic_timer then refires and the process repeats.

Everything resets itself at round start automatically, too. Nothing special is needed.




Quote
Re: Help with a jukebox!
Posted by Riven on Mon Aug 2nd at 11:25pm 2010


Ya, output delays can't be untoggled once they're started, regardless of the entity in question. Even if the entity is deleted after it has been triggered, and that output was given a delay, it will still fire, unless the target entity is missing too (the target entity could be itself).

I believe that's just a general "rule of thumb." In the future, if there's anything that may need to be stopped short before it's intended ending time, always stick with logic_timer. That's what that entity is for.

Nevertheless, it seems you've got it working, and is probably a lot less complicated for now!

Thanks for telling us the solution!

[EDIT]: Ok, I also just tested the code tag, and you're right, it doesn't enable free spacing. We're gonna need to look into that. Thanks for pointing that out. smiley







Post Reply