Multiple player.PreviousRoom == X

Started by rickious, Fri 17/04/2015 09:22:33

Previous topic - Next topic

rickious

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?
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

Gurok

#1
If I understand your code correctly, you could try:

Code: ags
  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:

Code: ags
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.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Monsieur OUXX

On an unrelated note, the absence of brackets is quite disturbing:

Code: ags

///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();

 

rickious

--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

rickious

Right...

now I have the following code.
Code: ags

  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  :)
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

Gurok

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:

Code: ags
    if(player.PreviousRoom == 7 || player.PreviousRoom == 6)
    {}
    else
    {
        Game.StopAudio();
        a03The_lab.Play();
        aDoor__generic__close.Play();
    }
[img]http://7d4iqnx.gif;rWRLUuw.gi

rickious

Just thought this myself.  It was a *DOH moment.

Thanks!
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!


SMF spam blocked by CleanTalk