Play character theme when changing player character

Started by Mats Berglinn, Sun 09/09/2007 14:09:20

Previous topic - Next topic

Mats Berglinn

Anyway, I've got a new question: In the current game I'm working in I would like to hear a short character theme played, before the real music plays, when you switch to other characters on the DOTT template (like in DOTT where you hear a short theme for Bernard, Hoagie or Laverne when switchen to one of them). I'm not sure how to script it but I've got Music 11 for first character theme, Music 12 as second and Music 13 for the third.
What do you think?

Mod Edit: Split from LucasArts GUI thread as it's not specific to that, and might be of use to others who wouldn't think of looking there.

Khris

When playing the character theme, start a timer.
When it expires, change the music to the default one.

Mats Berglinn

Could you show me some spefic scripting, please? Oh and in version 2.62 if you have forgotten.

Khris

I don't feel like doing all your work right now, sorry.

Mats Berglinn

Could you at least tell me where in the Global script I should put it in, please? I don't ask for fun you know.  :P

Ashen

Look up Timers in the manual and/or on the forums, and use a little common sense. You'd start it in interface_click, or where ever you change the player character, and check it in repeatedly_execute, since you need to check repeatedly whether it's expired.

However, reading the manual might suggest a simpler way: PlayMusicQueued (the link is to the online, 2.72 manual, but the multimedia functions haen't actually changed much, so it'll work in 2.62). Using PlayMusicQueued, you can play your character theme and queue up the 'real' music to start afterwards. The manual entry gives a pretty detailed example of how to use it.
I know what you're thinking ... Don't think that.

Mats Berglinn

I'm trying to make the character theme on the GUI scripts like this:

Code: ags
    if (button>=12){ //12 = first of the buttons for switching players / giving things by chron-o-john   
      int counter=1;
      while (counter<MAX_PLAYERS){
        if (Tposition[counter].smallpicbevelbutton==button){
          if (GetAGSMode(GetMode())==4 && ALLOW_CHRON_O_JOHN==1){
              GiveInvChronOJohn(game.inv_activated, Tposition[counter].charac);
          }
          else { 
        //  if (GetAGSMode(GetMode())==4) SetMode(DEFAULT);
          SetPlayer(Tposition[counter].charac);
          }
        }
        counter++;
      }
  }
         if (GetPlayerCharacter() == BERN){
         SetMusicRepeat(0);
         PlayMusicQueued(13);
     }
         if (GetPlayerCharacter() == HOAG){
         SetMusicRepeat(0);
         PlayMusicQueued(11);
   }
         if (GetPlayerCharacter() == LAVE){
         SetMusicRepeat(0);
         PlayMusicQueued(12);
   }


Well, so far I've just begun with the scripting so I haven't done the repeatedly_execute part yet but when I try to switch characters the themes aren't playing, the regular background music (music1 which by the way is marked as the music in the room that always plays due to it's marked as "Play music on room load") just keeps on playing.

What have I done wrong?

Ashen

Not read the example in the manual properly, at a guess. You've set the character theme to play queued - meaning it shouldn't start until AFTER the current track (started by changing rooms). What if you try:

Code: ags

         if (GetPlayerCharacter() == BERN){
         SetMusicRepeat(0);
         PlayMusic(13);
	 SetMusicRepeat(1);
	 PlayMusicQueued(1);
     }


It works exactly as expected, under 2.62. It shouldn't have any problems working along with the rest of the code you've got there, but ...


And if you use this method, you shouldn't need any repeatedly_execute scripting.
I know what you're thinking ... Don't think that.

Mats Berglinn

Actually I was reading the manual at that part but I wanted to test the character theme first, but now I know that was a mistake. Anyway, I've followed the example and it worked.

But there's something that still fuzzes me. If you play Music1 (which is used for many rooms in the game) then it would play in ALL the rooms even in those which have other music. How do you think I'll fix this? A GlobalInt maybe?

Ashen

Since you mentioned music1 specifically, I assumed it would always be that. Again, the answer is in the manual: GetCurrentMusic can be used before you play the chaacter theme, to find the music that should be playing:
Code: ags

         int TempI = GetCurrentMusic();
         SetMusicRepeat(0);
         PlayMusic(13);
	 SetMusicRepeat(1);
	 PlayMusicQueued(TempI);


Tested in 2.62 and seems to work.

Since I'm doing the work for you anyway, have a suggestion on the house: Why not use Custom Proprties to store the number of the character theme, to avoid haveing to replicate the code for all three:
Code: ags

         int TempI = GetCurrentMusic();
         SetMusicRepeat(0);
         PlayMusic(GetCharacterProperty(GetPlayerCharacter(), "Theme");
	 SetMusicRepeat(1);
	 PlayMusicQueued(TempI);


Should work for all characters.

NOTE: Changing the GetCharacterProperty(...) bit to player.GetProperty("Theme") should make this work in V2.72, as well. (You'll also need to update the change players part, obviously.)
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk