Can you create new commands using mygame.js


#1

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?


Add Individual sound effects to different pages?
#2

@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.


#3

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.


#4

This may help


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


#5

@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…


#6

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:


#7

Fantastic!

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


#8

@andymwhy

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


#9

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


#10

@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.


#11

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?


#12

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


#13

@P0RT3R in the mygame folder


#14

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


#15

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.


#16

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.


#17

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


#18

@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.


#19

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.


#20

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