Javascript sounds?

I 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?


Actually, 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.


REVISED

"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


NOTES

    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");

Many thanks. That looks like something I can use!


This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums