Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mats Berglinn on Sun 09/09/2007 14:09:20

Title: Play character theme when changing player character
Post by: Mats Berglinn on Sun 09/09/2007 14:09:20
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.
Title: Re: LucasArts GUI Help Thread <2.71 Now Available>
Post by: Khris on Thu 13/09/2007 19:23:01
When playing the character theme, start a timer.
When it expires, change the music to the default one.
Title: Re: LucasArts GUI Help Thread <2.71 Now Available>
Post by: Mats Berglinn on Thu 13/09/2007 21:30:23
Could you show me some spefic scripting, please? Oh and in version 2.62 if you have forgotten.
Title: Re: LucasArts GUI Help Thread <2.71 Now Available>
Post by: Khris on Fri 14/09/2007 00:28:49
I don't feel like doing all your work right now, sorry.
Title: Re: LucasArts GUI Help Thread <2.71 Now Available>
Post by: Mats Berglinn on Fri 14/09/2007 17:38:23
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
Title: Re: LucasArts GUI Help Thread <2.71 Now Available>
Post by: Ashen on Fri 14/09/2007 21:02:26
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 (http://www.adventuregamestudio.co.uk/manual/PlayMusicQueued.htm) (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.
Title: Re: LucasArts GUI Help Thread <2.71 Now Available>
Post by: Mats Berglinn on Sat 15/09/2007 12:15:09
I'm trying to make the character theme on the GUI scripts like this:

    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?
Title: Re: LucasArts GUI Help Thread <2.71 Now Available>
Post by: Ashen on Sat 15/09/2007 13:02:40
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:


         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.
Title: Re: LucasArts GUI Help Thread <2.71 Now Available>
Post by: Mats Berglinn on Sat 15/09/2007 13:27:05
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?
Title: Re: Play character theme when changing player character
Post by: Ashen on Sat 15/09/2007 13:34:22
Since you mentioned music1 specifically, I assumed it would always be that. Again, the answer is in the manual: GetCurrentMusic (http://www.adventuregamestudio.co.uk/manual/GetCurrentMusic.htm) can be used before you play the chaacter theme, to find the music that should be playing:

         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:

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