Javascript sounds?
![](https://i.imgur.com/6mfIIbhb.gif)
Bluevoss
02 Feb 2021, 17:23I might have a situation where I need to post a sound from a file using Javascript. Usually I just do it in squiffy but this appears in the middle of JS code and I'm kinda stuck. I looked at the examples in my references and couldn't make sense of them. So, is there a simple JS routine that will play a wav file?
![](https://i.imgur.com/6mfIIbhb.gif)
Bluevoss
02 Feb 2021, 17:30Actually, five minutes later I worked around it. Still, JS sounds might be needed so if you have a solution in your pocket, I'd like to see it.
K.V.
03 Feb 2021, 15:32REVISED
"Sorry, [I] can't post that here."
Here's working code, (somewhat) tested and approved (by me, so double check it!):
https://gist.github.com/KVonGit/0033fa33a1d6ad39d0ffa89f0a8e64e4#file-squiffy-adding-audio-via-js-md
K.V.
03 Feb 2021, 16:32NOTES
squiffy.ui.write("Hello, world!")
This function (which already exists in Squiffy) prints "Hello, world!" in the game, just like it would if that text were added to the game normally.
Function Variable Fun
squiffy.getEl = function(el){
return window.document.getElementById(el);
};
That seems to be the same as:
set("getEl", (el) => {
return window.document.getElementById(el);
})
(SIDENOTE: I type out 'window.document' because I've been fooling around with Electron apps, and just 'document' doesn't work in Electron sometimes.)
Also, I can "get" and use function variables like this:
let getEl = get ("getEl");
let el = getEl("output");
Or I can just directly access them:
let el = squiffy.getEl("output");
![](https://i.imgur.com/6mfIIbhb.gif)
Bluevoss
05 Feb 2021, 05:32Many thanks. That looks like something I can use!