I've been working on a game with sound & music, and want to use this sound macro (http://www.glorioustrainwrecks.com/node/5061
). I'm using Sugarcane in Twine 1, and when I start the game, I get this error message:
Error [Music Code]: Cannot read property 'firstChild' of null.
"Music Code" is what I named the Script passage that holds the macro.
The code works just fine when I test it in the Sugarcane format instead of Sugarcube; I don't get the error message in Sugarcane. In Sugarcane I always get the error, and no sound plays.
I can't just switch to Sugarcane though; that Sugarcube format is essential to my story. Does anyone know how I can fix this? Or, if there is no solution, is there an alternate code I can use that anyone knows of?
(In the past, I used the Howler extension for sound, but I had trouble using any other code but playing sound for it [I had trouble looping & stopping music].)
If you're using a recent release of SugarCube 2, and you should be, then simply use its built-in audio macros. To be frank, they're significantly better than the macros you're trying to use anyway.
As to why the train wreck macros aren't working. They're incompatible with any non-vanilla Twine 1 story formats, AFAIK.
As to Howler.js. You could use it in SugarCube, if its audio macros weren't to your liking. Though you'd probably either have to use a small wrapper with it or use SugarCube's user lib feature.
& ok, gotcha. Thank you. What do you mean by using a small wrapper or SugarCube's user lib feature? How do I do that?
I'd like to think that the current audio subsystem in SugarCube 2, and the macros which use it, is as good as Howler.js—I take some pride in that—and, yes, easier to use, however, I don't know if I'd say that it was better. On par, I suppose, I'd say. That said, Howler.js can do some things, like sprites, that I simply haven't felt the need to add to SugarCube's audio subsystem.
SugarCube 1's audio subsystem is similar to 2's, though not as advanced. The version in SugarCube 2 received a lot of love recently in release v2.8.0.
Moving on. Claretta has a point, @Norbez. Unless you need features like sprites, the built-in audio macros should probably do what you need—especially, if you though that the train wreck macros could do the job.
Wrapper first. Most libraries make assumptions about the environment within which they'll be evaluated. Most story formats evaluate user scripts in a way that is incompatible with those assumptions. To rectify this, you need to wrap the library within a small function which sets up an environment the library is happy with.
And userlib.js. It's simply a file you create within your SugarCube install directory, within which you paste the libraries you want to include—no wrapper necessary. It only works with Twine 1 style compilers (Twine 1, Twee, TweeGo), AFAIK.
Also, assuming I read the documentation correct, its global volume options are useless. It looks like if I want to adjust global volume, it simply assigns a new volume score to every track. So eg if one track was at 7 volume and one track was at 8, I can't just turn them both down, they'd both have to go to either 6 or 7. This seems to preclude adjusting volumes of tracks individually once in game to polish the audio.
It might just be a case of bad documentation, but global volume options need to adjust individual track volumes relative...