View Full Version : Jukebox

31st July 2010, 22:16
Nobody can guess what I'm doing with all these questions lately :rolleyes:

Ok, so I have a logic_case that randomly loops through a set of 7 songs. It needs to start turned off, and be able to be toggled on. Here are my outputs:


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 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. 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. Manually starting the entity in the new round results in two songs playing at once.

Could it have something to do with that fact that the entity is calling itself? I'm trying to come up with a way of calling some kind of sanity check entity instead of directly calling the next song... maybe a button that locks upon round start... If the button is locked, it can't play the next song and the chain breaks.

Any ideas?

31st July 2010, 23:54
The button idea is a partial solution... Here's what I have now:


Name: SongChooser

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



Name: SongChecker
Flags: Start Locked

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

The initial toggle for SongChooser unlocks 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.

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.

1st August 2010, 00:42
Still working on the super secret rave room, I see :rolleyes:

2nd August 2010, 01:01
Solved it with help from Zeph on the UberMicro mapping 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.

Name: SongTimer
OnTimer -> SongChooser -> PickRandom

Name: SongChooser
OnCase01 -> "Song1" -> PlaySound
OnCase01 -> "SongTimer" -> RefireTime -> "61" (or whatever the length of the song is)

Starting the jukebox enables the logic_timer, which calls PickRandom 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.

EDIT: Technically PickRandomShuffle is the better thing to call, but it doesn't seem to exist in Hidden. It doesn't fire, and it doesn't even come up in the console as an option with ent_fire. PickRandom is used instead.