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 :(. Hope you can still follow.)
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 [I]that[/I] 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:
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?