Infinite (rerun:) loop with HAL?

Twine Version: 2.9.2
Harlowe 3.3.9

Hi,
I’m using the Harlowe Audio Library to add audio into my game.
I’ve got it working fine in terms of the audio. I have managed to get the audio to perform actions when selecting appropriate buttons.
Currently I have my track file playing when the player selects the ‘play’ button which is then replaced by a ‘pause’ button before going back to ‘play’ when selected.
I can get this cycle to rerun twice using (rerun:) but after that it stops replacing ‘play’ with ‘pause’. I’m assuming I need to add something to my (rerun:) code for the Named Hook but I’m a bit stuck on where to go from here. I’d assume I need to create a loop but not sure how to go about that.
Is anyone able to help? Or is this something not possible in Harlowe?
(I’ve just used a random audio file I already had for now whilst I test everything out)

This is method one that I’ve tried that sort of works:

{
|play>
[(link-repeat:"▶")[(track:'new books', 'play')]
(link-repeat:"⏹")[(track:'new books','stop')]
[(click-replace:"▶")[(link-repeat:"⏸︎")[(track: 'new books', 'pause')]]
(click-replace:"⏸︎")[(link-repeat:"▶")[(track:'new books', 'play')]]]
 ]
(rerun:?play)
}

and this is method 2 making use of Named and Hidden Hooks:

|play>[(link-repeat:"▶")[(track:'new books', 'play')]]
(click-replace:"▶")[
		(show:?pause)[
        (rerun:?pause)]]
|pause)[
	(link-repeat:"⏸︎")[(track: 'new books', 'pause')]
    (link-repeat:"⏹")[(track:'new books','stop')]]
 (click-replace:"⏸︎")[
	
 	(hide:?pause)
    (show:?play)[(rerun:?play)]
    ]
 

I don’t have the HAL installed, but I believe your issue is basically toggling the buttons properly.

{
|play>[(link:"▶")[
	(replace: ?status)[PLAYING]
	(show: ?pause)
	(rerun: ?pause)
]] 
|pause)[(link:"⏸︎")[
	(replace: ?status)[PAUSED]
	(rerun: ?play)
]] 
|stop>[(link-repeat:"⏹")[
	(replace: ?status)[STOPPED]
	(hide: ?pause)
	(rerun: ?play)
]] 
}

Audio status: |status>[IDLE]

The code replaces a |status> hook message in place of controlling an audio file. However, if you click the buttons, the status reflects the state of what the audio file should be doing.

Note: Notice that the pause hook is initially hidden → |pause) and not |pause>

Let me know if this helps and if you have any other questions.

Thank you!!

I added in HAL’s custom macros and managed to get this to work perfectly!

 |status>[]
 {
|play>[(link:"▶")[
	(replace: ?status)[(track:'TRACK NAME','play')]
	(show: ?pause)
	(rerun: ?pause)
]] 
|pause)[(link:"⏸︎")[
	(replace: ?status)[(track:'TRACK NAME','pause')]
	(rerun: ?play)
]] 
|stop>[(link-repeat:"⏹")[
	(replace: ?status)[(track:'TRACK NAME','stop')]
	(hide: ?pause)
	(rerun: ?play)
]] 
}

Note: TRACK NAME is the name of the required track you want the audio playing that you’ve set up in the hal.config passage.
I left the status Named Hook blank as there is no IDLE within HAL but I guess you could put the preload macro here if you haven’t set audio to preload.

I’m not familiar with HAL. Is there a reason why you can’t run…

(track:'TRACK NAME','play')

…in place of…

(replace: ?status)[(track:'TRACK NAME','play')]

and just get rid of the |status> hook altogether?

There is no reason - you 100% can. I don’t know why I just didn’t do that, there’s no need for |status> at all.

Cool. I only created a |status> hook for illustrative purposes.

1 Like