|
Post by Doan the Nado on Nov 30, 2004 20:19:49 GMT -5
This is a very exciting advancement in custom music, as I don't think it has been done before. Vespuleth gave me the idea a while back and I came up with a way to make it work. It IS possible to make custom music play uninterrupted during gameplay, even while content scripts are running. Here is how I did it:
First of all, you will need 2 main scripts to play the music, scripts that I will call "jukeboxes". The first is the Action Jukebox, which is used to play the music during gameplay, while the player is walking around. The second is the Content Jukebox, which plays the music while an object is being examined. The Action Jukebox must be placed in an event's motion slot and placed on every map that you want custom music to play. The scripts only require one variable and one flag, so I will call them "Variable" and "Flag" respectively. Here are the two scripts:
Action Jukebox Variable = 0 Repeat forever Call: Music Playing Script Call: Counter Wait 1F End Repeat
Content Jukebox Repeat while Flag is On Call: Music Playing Script Call: Counter Wait 1F End Repeat
Those are the key scripts that make this entire thing possible. I will now try my best to explain the music playing scripts, and how they must be written. I think that it actually makes music writing much simpler. Here is an example of a music script:
Wait 4F SFX1 Wait 12F SFX2 SFX3 Wait 8F SFX4 Wait 8F SFX5 SFX6
Now if you check the wait numbers, you can see that SFX1 is played at frame 4, SFX2&3 at frame 16, SFX4 at frame 24, and SFX5&6 at frame 32. For the system I wrote to work, you will have to write your instrumental pieces as follows:
Sort Variable Apply If 4 SFX1 To End Apply If 16 SFX2 SFX3 To End Apply If 24 SFX4 To End Apply If 32 SFX5 SFX6 Branch End
You may have your instruments each split up into their own scripts. That is fine, as long as each part is written as shown above. Your song script would look like this:
Call Instrument1 Call Instrument2 Call Instrument3
and so on. That's it. Now, above I alluded to a "Music Playing" script. This will allow you to have however many different songs you want. You'll have to set some variable (I'll call it Song) to a certain value depending on what song you want to play. This will be done in the Enter Map script or wherever. Your Music playing script will look like:
Sort Song Apply If 1 Call Song1 To End Apply If 2 Call Song2 To End Apply If... ... Branch End
So now that you have your songs, you need to know how they will play. Both Jukebox scripts work by calling these sorted songs, which play the right note according to the Variable. The counter script increase the variable by 1, and that occurs once every frame, after the Jukebox waits a frame. The counter script is simple: Variable = Variable + 1.
The easiest way to handle a song end is to make one of the instrument scripts reset Variable to 0 when it gets to the end of the song. There are other ways to reset the variable, but that is probably the most efficient.
Finally, the important thing is what to do when events are examined. It is really quite easy, but will involve making slight changes to every content script that runs during gameplay ([] script and events with apply scripts). It may be more efficient to put the flag commands in separate scripts and call them, but here's the structure:
Flag = On Apply Together Call Content Jukebox Everything the event does here (Message windows, movement, anything) Flag = Off
That's it: you just have to add the first 3 lines and the last line to every event, and you will have non-stop, seamless music. If anything needs clarification, be sure to ask.
|
|
|
Post by doyleman on Nov 30, 2004 20:30:03 GMT -5
Yaay! now if i can figure out how the Music script maker works, i can use songs in my game!
|
|
|
Post by The Final Rune on Dec 1, 2004 12:04:10 GMT -5
Wow, that would make some things a lot easier. Yay for all my custom music!
Thanks Doan and Ves!
|
|
|
Post by Doan the Nado on Dec 1, 2004 14:22:32 GMT -5
In case you want to understand how this system works, I will try to explain it here. The key element is the interaction between the content and action script through the use of the shared Variable. Variable keeps track of how far along the song is. Since variables can go up to 99999999, that works out to 38 days, 13 hours, 55 minutes, and 33.3 seconds. There is no possible way you could write a song that long, so variable can keep track of where the song is at, frame-by-frame, without danger of getting too high for the system.
Both Jukeboxes work by adding 1 to Variable every frame, so that it holds the length of time, in frames, that the song has been playing. The song script is then called, which plays certain SFX at certain frames.
Normally, the song is playing through an action script. Action Jukebox sets Variable to 0 so that the song starts from the top when you enter the map. Variable begins changing the moment the Enter Map script completes. When a content script runs, all action scripts are paused (excluding VFX animations), including Action Jukebox. For this reason, it is necessary for the Content Jukebox to take over.
Since it works the same way as the Action Jukebox, the Content Jukebox picks up right where the action script left off. When Apply Together is used as it is in the Content Jukebox, two content scripts can run simultaneously (Content Jukebox and the event's script). The only hang up here is that the Content Jukebox must be stopped when the event's scripts are complete. That is accomplished with the use of Flag as the repeating condition for the Content Jukebox. When the content script begins, Flag is turned on so that the Content Jukebox can run. When the script completes, the flag is turned off, and the Content Jukebox script ends. Since all content scripts have completed, the action scripts resume, including Action Jukebox, which picks up right where Content Jukebox left off.
The nature of the Apply Together command lends itself to an important element of writing scripts like these. If you have a content script that has Apply Together or Apply In Order commands in it (or if you need the script to execute in order), you will have to write the script separately and call it, so that the structure looks like this:
000 Flag = On 001 Apply Together 002 Call: Content Jukebox 003 Call: Event's Script 004 Flag = Off
This is necessary because the "Flag = Off" command MUST be Applied Together with the Content Jukebox command, or else it can never end the Jukebox. If any Apply In Order commands are placed between line 2 and line 4, the script will never end, and the game will "freeze up" (music will continue playing, but the player will be able to do nothing).
That's about it for the explanation. Next comes some more in-depth song-writing tips, and other ways this song-writing method is more efficient.
|
|
|
Post by The Final Rune on Dec 1, 2004 14:34:02 GMT -5
sometime, like at 3 in the morning while tossing and turning on my crappy air mattress, I come up with apifanies (not sure hot to spell it) like these, unfortunately by the time I walk in to the living room, turn on the TV and boot up the game I've already forgotten it.
Maybe I should just write it down and go back to sleep instead.
|
|
|
Post by Doan the Nado on Dec 1, 2004 14:48:51 GMT -5
It may seem as though updating Variable frame-by-frame will make song-writing more complicating, but it actually simplifies the process because it eliminates wait commands. If you decide that a measure should last about 2 seconds, you can assign the length of a measure to be 64 frames, which makes the music writing amazingly easy. In 4/4 time, a whole note would last 64 frames, a half note 32, quarter note 16, eighth note 8, and so on. This means that if you have a piece that goes:
1/16 1/16 1/4 1/8 1/2 | 1
your notes song script would go:
Sort Variable Apply If 0 Note1 To End Apply If 4 Note2 To End Apply If 8 Note3 To End Apply If 24 Note4 To End Apply If 32 Note5 To End Apply If 64 Note6 Branch End
So you see that writing music now involves simply numbering your different notes so that you can see what frame they should be played at.
I mentioned that it will increase efficiency, and here's how: Let's assume the Volume, Pan, and Tempo of all the notes are the same. I know whole notes should be longer, and so on, but bear with me for example's sake. Now in the example above, let's say the note sequence is ABCDDC. This would mean that Note3 and Note6 are identical, and Note4 and Note5 are identical. You can now write your script like this:
Sort Variable Apply If 0 Note1 To End Apply If 4 Note2 To End Apply If 8 Apply If 64 Note3/6 To End Apply If 24 Apply If 32 Note4/5 Branch End
That could potentially cut the music length down considerably, as identical notes would only have to be put in one time. In fact, you could realistically write a script for a bass guitar that would last the entire song, playing 5 different half and whole notes, that would only use 10 SFX commands. The rest would all be Apply Ifs.
Another good thing about writing songs this way is that it easily allows you to play the identical parts without having to write them more than once. Let's say there is a chorus that first plays from Variable=1000 to Variable=1400. If you want this chorus to repeat at 2400, 3800, and 5200, it would be easy to do. You could use a TempVariable that was based on Variable:
Temp Variable = Variable If Variable >= 2400 If Variable <= 2800 Temp Variable = Variable - 1400 Condition End Condition End If Variable >= 3800 If Variable <= 4200 Temp Variable = Variable - 2800 Condition End Condition End If Variable >= 5200 If Variable <= 5600 Temp Variable = Variable - 4200 Condition End Condition End Sort Temp Variable Apply If ... ... Apply If 1000 Chorus Note1 To End Apply If 1016 Chorus Note2 Apply If ... ... Apply If 1400 Final Chorus Note To End Apply If ... ... Branch End
By playing the instrument's sound based on the value of TempVariable, you can maintain your place in the song (using Variable) while still repeating previous parts without writing a bunch of Apply Ifs.
An important note about changing the value of Variable: Let's say you get to the end of the song and you want to start it again from the beginning. I said before that you could add a Variable = 0 (or even better, Variable = -1) command to one of your instruments. It is important to add it to the LAST CALLED INSTRUMENT in the song script. For example, if you have a song script that goes:
Call: Instrument1 Call: Instrument2 Call: Instrument3
it is important to place the Variable = 0 command in the script for Instrument3, or else the final notes for 1 and 2 will not be played. This is merely a consequence of script execution. Although the three scripts execute seemingly simultaneously, they are actually occuring in order extremely quickly.
That's all for the music lessons. Good luck with your new and improved song writing.
|
|
|
Post by Dungeon Warden on Dec 1, 2004 14:51:20 GMT -5
I have a question about the sort command. Am I to believe that the apply if command will use the = sign as a > sign? i.e. if Variable is between 4 and 16, the apply if = 4 will be activated. I was wondering if I could do this, but I guess I never tried. This will help me in one of my scripts if it works. Thanks for pointing it out.
|
|
|
Post by Doan the Nado on Dec 1, 2004 14:58:02 GMT -5
No, it will work as an = sign. You only want your notes to play once. Song scripts used to be written like:
Note1 Wait 4f Note2 Wait 4f Note3 Wait 16f Note4 Wait 8f ...
Therefore, using the Jukeboxes' counter methods,
Sort Variable Apply If 0 Note1 To End (+4f) Apply If 4 Note2 To End (+4f) Apply If 8 Note3 To End (+16f) Apply If 24 Note4 To End (+8f) Apply If 32 ...
would be the same exact thing. The notes only play once, when the variable holds the value for the point at which they should be played.
|
|
|
Post by Dungeon Warden on Dec 1, 2004 15:52:52 GMT -5
So, does a note play until the next one starts, or is it silent between notes? Sorry, I never played around with making music much.
Darn, I was hoping that Apply if trick would work. Oh well, back to the drawing board.
|
|
|
Post by Doan the Nado on Dec 1, 2004 16:30:40 GMT -5
SFX have a tempo value that can be changed, but it's sometimes not really necessary. If you're writing a guitar piece, for example, the important thing is really WHEN the note is played, not how long it lasts. For some wind instruments and pianos, however, you will have to do some experimentation to figure out how high the tempo value should be for each note. Jugem, I know you've played around with this quite a bit. Do you know how the tempo and frame length is related for each instrument? If not, I'll do some testing to try to figure it out. It may even vary depending on the instrument.
|
|
|
Post by Jugem on Dec 1, 2004 16:32:34 GMT -5
So, does a note play until the next one starts, or is it silent between notes? Sorry, I never played around with making music much. The notes' lengths depend on the tempo setting for the SFX. That's a lot to read through, but thanks for finally getting this up Doan. I think I got the just of it, but I'll have to take closer look and try it out later.
|
|
|
Post by Doan the Nado on Dec 1, 2004 16:34:01 GMT -5
My first post gives the exact scripts, but the second one and third one explain better how it works and how you can make it work for you. It may help to read the second post before the first one.
|
|
|
Post by Jugem on Dec 1, 2004 16:34:42 GMT -5
Jugem, I know you've played around with this quite a bit. Do you know how the tempo and frame length is related for each instrument? If not, I'll do some testing to try to figure it out. It may even vary depending on the instrument. I probably have it written down somewhere; just not with me right now. You can check my music scripts in my demo to find various tempo settings for different instrument/frame wait combinations. The music scripts all have a (#) in the script name. EDIT: I understood it fine in the first post. I've read it more thoroughly now, and I'll have to try it out tonight. I'll let you know the results of that tomorrow, hopefully.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Dec 1, 2004 17:50:29 GMT -5
Sorry it's slightly off topic, but probably'll still help people. Does anyone know what pitches on the guitar sounds correlate to what notes (it doesn't say in the music scripting faq)? I don't need to know right away, and thank you if anyone answers.
|
|
|
Post by Doan the Nado on Dec 1, 2004 17:53:21 GMT -5
I don't mind the off-topicness too much, but it may be a good idea to start a new topic for this. In there, we can post all the info we learn about pitches for different instruments. In a topic of its own, it would be more easily found later on.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Dec 1, 2004 17:56:00 GMT -5
Okay, I'll be lazy and let someone else start it. ;D Thank you.
|
|
|
Post by The Final Rune on Dec 1, 2004 18:30:49 GMT -5
Props to Doan!
You the MAN! Doan!
|
|
|
Post by Jugem on Dec 2, 2004 13:45:10 GMT -5
I tested it out, and found one problem. It worked fine when you added those extra lines to a content script that didn't have an apply in order command. But if you need to use apply in order, you suggested calling a script that contained all that stuff. Have you actually tried that out, because it wouldn't work for me. I think it executed the first line in the script, but the rest of the called script was ignored.
Oh, and another use for your idea would be to keep music going across maps (except of course when the new map is loading). Just don't reset the variable at the start of the action script.
|
|
|
Post by Doan the Nado on Dec 2, 2004 14:01:40 GMT -5
No, I didn't test out the calling script method. That could potentially limit the uses for custom music on some maps. It seemed like it would logically work, but I guess not. I'll check this out soon and let you know what I come up with.
If this is indeed a problem, it is still only a small setback. Most of the examinable events won't require apply in order commands, and the ones that already do may be able to be re-written to effectively be applied in order. Wait commands will still work fine when applied together, so let's say you had a script like this, applied in order:
Walk to party in 15F Say Something Walk North, 10F Walk East, 5F Remove Event
You could write your applied together script like this:
Flag = On Apply Together Call: Content Jukebox Walk to party in 15F Wait 15F Say Something Walk North, 10F Wait 10F Walk East, 5F Wait 5F Remove Event Flag = Off
That's just one example of a way to get around this problem. It is cumbersome, but it leaves hope that even if RPGM2 doesn't work exactly the way I'd hoped, it will still be serviceable.
|
|
|
Post by Jugem on Dec 2, 2004 14:10:59 GMT -5
I don't think that's the best example to use, since those event move commands aren't able to apply together anyway. But I understand what you're getting at. That seems like it would solve the problem...Didn't get around to thinking of a solution for that except for trying to eliminate the apply in order commands.
|
|
|
Post by Doan the Nado on Dec 2, 2004 14:21:04 GMT -5
Ahh yes, you're right. That was a horrible example. But if it was for camera control commands, or some other command that could be applied together (and you wanted it to be applied in order), that would be one way to do that. I know you know that, but I want to clarify for everyone else.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jan 5, 2005 2:41:14 GMT -5
Yes, thank you very much Doan, I may be using this method in my game for a song or two.
I tried my hand at figuring out the guitar pitches and I think Guitar 1 -> -6 = C and Bass -> 0 = B, but I'm not sure.
Sounds very good.
|
|
|
Post by vespuleth on Jan 5, 2005 14:19:23 GMT -5
Oblivion Dragon wrote a music composition faq thats available at the mag that might be of some help to you, will. it had pitch comparisons in it.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jan 5, 2005 23:00:53 GMT -5
I've seen it already, but he didn't have guitar or bass on it, but only piano, flute, etc. (which I used for those instruments), but thanks any ways.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Feb 21, 2005 5:11:36 GMT -5
Wait though, wouldn't making a text message, shop menu or multiple choice come up in a content script stop the music then? Has anyone gotten this to work flawlessly while talking to townspeople and shopkeepers? I'll try my hand at it somewhat soon, but has anyone perfected this yet?!
Edit:
I tried it too and it didn't work. Have you found a way to do what Jugem said? If not this means that anything dependent on the player pressing something can't go while the music does (it seems to me). I've looked over everything I've done a ton, and I've done what you said exactly (with calling a script and a text message), it's not my script that actually plays the sounds, but something before it that's messing it up. I've changed things up a lot to try different things and nothing's worked either.
|
|