Playing different musics

Started by Mats Berglinn, Wed 15/11/2006 15:39:42

Previous topic - Next topic

Mats Berglinn

I've a little problem with a fun feature for my current game.

In one of the rooms there is a stereo that you can play different kinds of music. It's meant that you play different music each time you "Use" the stereo, through the files MUSIC5.mp3 to MUSIC14.mp3 and then finally you turn off the stereo and the regular background music is heard. After that you start over with the music.

The problem is that when it does start over it doesn't play the "first" music, but the second one.

This is how the script for the function works:

Code: ags
if (music == 0) {
Ã,  Ã,  DisplaySpeech(BERN,"I'll turn on some music.");
Ã,  Ã,  PlayMusic(5);
Ã,  }
Ã,  Ã,  if (music == 1) {
Ã,  Ã,  PlayMusic(6);Ã,  
Ã,  }
Ã,  Ã,  if (music == 2) {
Ã,  Ã,  PlayMusic(7);
Ã,  }
Ã,  if (music == 3) {
Ã,  Ã,  PlayMusic(8);Ã,  
Ã,  }
Ã,  Ã,  if (music == 4) {
Ã,  Ã,  PlayMusic(9);Ã,  
Ã,  }
Ã,  Ã,  if (music == 5) {
Ã,  Ã,  PlayMusic(10);Ã,  
Ã,  }
Ã,  Ã,  if (music == 6) {
Ã,  Ã,  PlayMusic(11);Ã,  
Ã,  }
Ã,  Ã,  if (music == 7) {
Ã,  Ã,  PlayMusic(12);Ã,  
Ã,  }
Ã,  Ã,  if (music == 8) {
Ã,  Ã,  PlayMusic(13);Ã,  
Ã,  Ã,  music = 9;
Ã,  }
Ã,  Ã,  if (music == 9) {
Ã,  Ã,  PlayMusic(14);Ã,  
Ã,  }
Ã,  Ã,  if (music == 10) {
Ã,  Ã,  DisplaySpeech(BERN,"I'll turn it off.");
Ã,  Ã,  PlayMusic(2);
Ã,  Ã,  music = 0;
Ã,  }Ã,  
Ã,  if (music < 10) {
Ã,  Ã,  music += 1;
}


I think the problem is that once it hits music = 0 again, it will skip over to music = 1 but I've no idea how to solve this.

Note: I'm using 2.62 version.

BOYD1981

i did a similar thing to this in my game 'I Need A Wee', for that i just had 5 different radio station preset buttons and used hotspots, but that wouldn't be much help to you.
but one thing you could try, and is probably the way i'd achieve something like this is make the stereo itself several characters and set it up so that when you interact with it the music plays but the character also disappears and another character using the same stereo sprite appears which would play a different tune when interacted with and also make another character appear who's interaction is to play another file and so on (i did a similar thing to make the radio LED display show a different station name).
this is the code i used which i first put in the room script for player entering screen
Code: ags

cRadio.on = true;
cRadio.Clickable = 1;
cMusic1.on = false;
cMusic1.Clickable = 0;
cMusic2.on = false;
cMusic2.Clickable = 0;
cMusic3.on = false;
cMusic3.Clickable = 0;
cMusic4.on = false;
cMusic4.Clickable = 0;
cMusic5.on = false;
cMusic5.Clickable = 0;


then when you clicked on a numbered button (which was just a hotspot) i had this
Code: ags

PlayMusic(1);  
cRadio.on = false;
cRadio.Clickable = 0;
cMusic1.on = true;
cMusic1.Clickable = 1;
cMusic2.on = false;
cMusic2.Clickable = 0;
cMusic3.on = false;
cMusic3.Clickable = 0;
cMusic4.on = false;
cMusic4.Clickable = 0;
cMusic5.on = false;
cMusic5.Clickable = 0;


it makes the radio character (which is just the LED reading telling you the model number) become invisible and unclickable. the same code should apply to character interaction.
hope i haven't totally confused you.

Limey Lizard, Waste Wizard!
01101101011000010110010001100101001000000111100101101111011101010010000001101100011011110110111101101011

Ashen

Boyd, he said he's using 2.62, that code won't work. (And seems a bit of an overly complicated way to do it anyway...)
You could either change the music = 0; line in the if (music == 10) condition to music = -1; (so that the later music += 1; makes it 0), or remove it completely and make it:
Code: ags

  if (music == 10) {
    DisplaySpeech(BERN,"I'll turn it off.");
    PlayMusic(2);
  } 
  if (music < 10) {
    music += 1;
  }
  else music = 0; // i.e. 'if (music == 10)' again
I know what you're thinking ... Don't think that.

Mats Berglinn

Thanks Ashen, it worked this time. You are a very helpful AGSer. Thanks once again.

Khris

1. You don't need all the {}s, if there's only one command inside, they are redundant.
2. All those ifs in the middle are equivalent to:
Code: ags
if (music>=1 && music <=9) PlayMusic(music+5);
except that using my code won't skip Music 13.

SMF spam blocked by CleanTalk