Can you create new commands using mygame.js

Specifically, can you load up an audio file in index.html. And then create JavaScript *functions in mygame.js that reference to that audio file (pause, play) that when inputed into your scene files as a command (or just the raw function) will play the audio you loaded up in index.html when you type in the “play” command/function automatically and vice versa?

Anybody know?

@Malebranche
I am sure if you have the skill you could add it to mygame.js, but they do not encourage such discussions here. More then likely it would not be supported by CoG. I know you can add it to the index. Would have to do a search here on the board on how to do so.

It’s possible, i’m sure there was an example of a game that had it but that was a long time ago…as for how…no clue.

This may help


Also look at the code for some of the games that already have music in them.

@Lordirish, that link is useful to add music to your game, the way Blackraven (WIP) and Trial of the Demon Hunter (HG) have. However, it doesn’t explain how to add music cues to start or end the music at a given scene. I guess it would involve creating a new choicescript command, of which I have no idea how to do…

Gentlemen, may I be proud to announce:

IT WORKS!!!

And it does exactly what I want it to do, with commands enabling you to play and pause audio at will.

You have to paste this code:

`


`

in your index.html file (replace “coolaudio” with the name of your audio file) and then use this command in CS (its actually one of the default CS commands):

To play track
*script playAud()

To pause track
*script pauseAud()

If you want multiple tracks, simply create more functions and variables in your index.html file like so:

`


`

Have fun… :wink:

1 Like

Fantastic!

I can sense a PM from Sam coming asking for individual track files for DH part2…

@andymwhy

lol, you could say your demon hunter senses are tingling :))

@andymwhy
I think you already sent them. :slight_smile:

@Malebranche
Good job! You’re a genius!

@jasonstevanhill
Would this be able to go into a published app?

@Samuel_H_Young

Oh, I don’t know about genius and all that, after all, P0RT3R was the one who mentioned the *script command in the first place (in HornHeadFan’s Game soundtrack thread), and I just ad-libbed the java script from a W3schools html example.

I am so happy now.

And i only copied those commands from what was told to me in my cs help discussion

And for the music itself, where do you put those? Just throw a mp3 and ?ogg? In the web folder?

@Malebranche
Ah, okay :stuck_out_tongue_winking_eye: well thanks to you, either way, and @P0RT3R as well

@P0RT3R in the mygame folder

Ok! Now i can add intro music and music at the end of my games!

I don’t really get why such discussions are frowned upon? Seems like there could be a sub section for it at least. This is very cool.

I might be the odd one out here, but I’d caution you guys to think very carefully before you put music or sound into your games. The main virtue of this kind of game is that it is lightweight and has low requirements. Music will jack up the file size immensely, and I’m probably not alone in playing games muted anyway. Sam’ll hate me, but I feel the same way about pictures. I’d prefer text only, none of this extra stuff.

To each their own, but I think it’ll add to the story in my opinion. A chorus of string instruments playing sharp and drawn out notes could really amp up the setting a haunted crypt would give off or old jazz would of worked perfectly in games like Life of a Mobster in a speakeasy scene

@TumTum
Even though it does increase the file size, you don’t have to otherwise acknowledge the music or illustrations. The music starts off paused, and you can skip over the images. Many others, including me, though, think they add flavor.

Yes, you can do it that way or even make proper commands by extending the Scene object (via prototype) and adding it to the valid commands object.

You can do anything you can usually do with HTML/JS/CSS, the real question is whether or not COG will publish it. But please, if you’re going to this don’t use a separate function and command for every track, look up some JS tutorials and use function parameters.

I use function in my whip so I can call the soundeffects files with a *script.