Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: rickious on Fri 17/04/2015 09:22:33

Title: Multiple player.PreviousRoom == X
Post by: rickious on Fri 17/04/2015 09:22:33
So, I have a basic thing I do with most rooms where it stops the previous music, then plays that rooms music.  BUT I have 2 closeups in a room, where i dont want this to happen.  I used...

  if   (player.PreviousRoom == 7){}
    else
    Game.StopAudio();
    a03The_lab.Play();

Which I can prevent this happening if you enter back into the parent room from room 7.  But I want to add room 6 too.  I either break both or only get one working at a time.

Any ideas?
Title: Re: Multiple player.PreviousRoom == X
Post by: Gurok on Fri 17/04/2015 09:27:09
If I understand your code correctly, you could try:

  if   (player.PreviousRoom == 7 || player.PreviousRoom == 6){}
    else
    Game.StopAudio();
    a03The_lab.Play();


If the previous room is 7 *OR* the previous room is 6.



Which you could rewrite more simply as:

if(player.PreviousRoom != 7 && player.PreviousRoom != 6)
    Game.StopAudio();
a03The_lab.Play();


This is the logical inverse -- If the previous room is not 7 *AND* the previous room is not 6.


Also, only the first statement is contained within the conditional block. From the indentation, it's not clear if that's what you intended.
Title: Re: Multiple player.PreviousRoom == X
Post by: Monsieur OUXX on Fri 17/04/2015 09:32:04
On an unrelated note, the absence of brackets is quite disturbing:

Code (ags) Select

///YOU CAN DO THIS:
else
{
    Game.StopAudio();
    a03The_lab.Play();
}

//...OR THIS:
else
    Game.StopAudio();

a03The_lab.Play();

//...BUT NEVER THIS:
else
    Game.StopAudio();
    a03The_lab.Play();

Title: Re: Multiple player.PreviousRoom == X
Post by: rickious on Fri 17/04/2015 09:56:14
Quote from: Monsieur OUXX on Fri 17/04/2015 09:32:04
On an unrelated note, the absence of brackets is quite disturbing:
(laugh)
Title: Re: Multiple player.PreviousRoom == X
Post by: rickious on Fri 17/04/2015 10:22:27
Right...

now I have the following code.
Code (ags) Select

  if   (player.PreviousRoom == 7 || player.PreviousRoom == 6){}
    else
    Game.StopAudio();
    a03The_lab.Play();
    aDoor__generic__close.Play();


If I havent come from room 6 or 7, it does not do...
    Game.StopAudio();
    a03The_lab.Play();

but still does...
    aDoor__generic__close.Play();

any ideas  :)
Title: Re: Multiple player.PreviousRoom == X
Post by: Gurok on Fri 17/04/2015 10:29:24
The code above will execute a03The_lab.Play() and aDoor__generic__close.Play() regardless of the result of the if statement.

Use braces to group the statements into a code block:

    if(player.PreviousRoom == 7 || player.PreviousRoom == 6)
    {}
    else
    {
        Game.StopAudio();
        a03The_lab.Play();
        aDoor__generic__close.Play();
    }
Title: Re: Multiple player.PreviousRoom == X
Post by: rickious on Fri 17/04/2015 10:42:10
Just thought this myself.  It was a *DOH moment.

Thanks!
Title: Re: Multiple player.PreviousRoom == X
Post by: Khris on Fri 17/04/2015 11:08:17
For a slightly more robust solution, try this:
http://www.adventuregamestudio.co.uk/forums/index.php?topic=50363.msg636486911#msg636486911