Multiple 'if' with 'ChangeRoom' [SOLVED]

Started by rickious, Tue 01/10/2013 21:25:29

Previous topic - Next topic

rickious

I am using a multiple 'if' 'Bool' on a room transition.

Your in a cell, you can look at the sink to open a 1st person view room of the sink.  You can put the plug in and fill the sink, I have used 3 separate rooms for this, and when you put the plug in, it triggers the first 'Bool', fill the sink, the ssecond 'bool'....

The bools are so that if the player leaves the sink view and returns, they go to the correct view of the sink.

When I exit the sink at the plugin or filled point, the game crashes when I try to view it again...

'NewRoom: Cannot run this command, since there is a NewRoom command already queued to run'

Code: ags
{
  if (PlugIn==true)
  {
    cEgo.Walk(575, 650, eBlock, eWalkableAreas);
    cEgo.ChangeRoom(8, 0, 0);
  }
  if (SinkFilled==true)
  {
    cEgo.Walk(575, 650, eBlock, eWalkableAreas);
    cEgo.ChangeRoom(9, 0, 0);
  }
  else
  {
    cEgo.Walk(575, 650, eBlock, eWalkableAreas);
    cEgo.ChangeRoom(2, 0, 0);
  }
}


Any ideas? Seems like its trying to run two ChangeRoom commands at once.

I have 2 bools setup for this in Global Variables.
PlugIn   bool   false
SinkFilled   bool   false
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

Crimson Wizard

#1
Yes, your code allows to run two ChangeRoom commands in a sequence.
First is run if PlugIn = true, and then the second runs if SinkFilled is either true or false.

To deal with situations like this you need to exit the function prematurely. This is what "return" command for ().

Code: ags

{
  if (PlugIn==true)
  {
    cEgo.Walk(575, 650, eBlock, eWalkableAreas);
    cEgo.ChangeRoom(8, 0, 0);
    return; // this terminates function and returns back to where it was called
  }
  <...>
}


Another way is to use "else if" structure, in which case only one of the blocks can be processed at a time:
Code: ags

{
  if (PlugIn==true)
  {
    cEgo.Walk(575, 650, eBlock, eWalkableAreas);
    cEgo.ChangeRoom(8, 0, 0);
  }
  else if (SinkFilled==true)
  {
    cEgo.Walk(575, 650, eBlock, eWalkableAreas);
    cEgo.ChangeRoom(9, 0, 0);
  }
  else
  {
    cEgo.Walk(575, 650, eBlock, eWalkableAreas);
    cEgo.ChangeRoom(2, 0, 0);
  }
}

I actually think that the second solution is better in this particular case, because you do not have anything else in this function.

rickious

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

Body Pharm - coming soon!

rickious

Hmm, Almost solved.

PlugIn works fine, when you go to room 8, it runs...
Code: ags
SinkFilled = true;

but when I leave the SinkFilled view and go back, it goes back to the PlugIn view... :-\
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

rickious

Ah sorted it now.  Had to add 'PlugIn = false' when entering the SinkFilled room.
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

SMF spam blocked by CleanTalk