Intersecting rooms problem

Started by Morgan, Sun 11/01/2009 19:56:48

Previous topic - Next topic

Morgan

I have a room with a bathroom connected to it and the two rooms are separated by a door. The door is an object in the room and in the interact with object area I put this code:

if (character[0].y > 131) { // character is standing in walkable area 1
      character[0].Walk(127,131,eBlock); //walk to door from walkable area 1
}
else {
      character[0].Walk(127,92,eBlock); //walk to door from walkable area 2
}

if (GetGlobalInt(28) == 0) { // if the Globalint is 0 (the default)
    // open door:
      SetObjectView(3,2); // open door view
    SetGlobalInt(28, 1); // set GlobalInt to 1 so the door will be closed on next interaction
  }
  else { // if GlobalInt is not 0, i.e. 1
    // close door:
      SetObjectView(3, 3); // closed door view
      SetGlobalInt(28, 0); // reset GlobalInt to 0 so door will be openend next time
  }

this works very well except I can't get it so when your in the main room (walkable area 1) AND the door is closed it removes walkable area 2 and vise versa but when the door is open both walkable areas are restored. And I'm not very knowledgeable with coding. what I have now is mainly trial and error and help from the forums so be as specific as you can.

Dualnames

if (character[0].y > 131) { // character is standing in walkable area 1
character[0].Walk(127,131,eBlock); //walk to door from walkable area 1
}
else {
character[0].Walk(127,92,eBlock); //walk to door from walkable area 2
}

if (GetGlobalInt(28) == 0) { // if the Globalint is 0 (the default)
    // open door:
      SetObjectView(3,2); // open door view
    SetGlobalInt(28, 1); // set GlobalInt to 1 so the door will be closed on next interaction
return;//without this the script will carry on and thus do what you wish not.
  }
  else { // if GlobalInt is not 0, i.e. 1
    // close door:
      SetObjectView(3, 3); // closed door view
      SetGlobalInt(28, 0); // reset GlobalInt to 0 so door will be openend next time
  }

All should be fine now. If not place some returns accordingly and it will be.

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Matti

#2
Dualnames, I think he's looking for something else. I hope I haven't messed up things so this will work:

Code: ags

if (character[0].y > 131) { // character is standing in walkable area 1
  character[0].Walk(127,131,eBlock); //walk to door from walkable area 1

  if (GetGlobalInt(28) == 0) { // if the Globalint is 0 (the default)
      SetObjectView(3,2); // open door view
      SetGlobalInt(28, 1); // set GlobalInt to 1 so the door will be closed next time
      RestoreWalkableArea(2);
  }
  else if (GetGlobalInt(28) == 1) { // if the Globalint is 1
      SetObjectView(3, 3); // closed door view
      SetGlobalInt(28, 0); // reset GlobalInt to 0 so door will be openend next time
      RemoveWalkableArea(2);
  }
}
else { // character is standing in walkable area 2
      character[0].Walk(127,92,eBlock); //walk to door from walkable area 2

  if (GetGlobalInt(28) == 0) { // if the Globalint is 0 (the default)
      SetObjectView(3,2); // open door view
      SetGlobalInt(28, 1); // set GlobalInt to 1 so the door will be closed next time
      RestoreWalkableArea(1);
  }
  else if (GetGlobalInt(28) == 1) { // if the Globalint is 1
      SetObjectView(3, 3); // closed door view
      SetGlobalInt(28, 0); // reset GlobalInt to 0 so door will be openend next time
      RemoveWalkableArea(1);
  }
}


Try that out and let me know if it worked. Note that you have to post the removewalkeablearea code int the rooms before_fadein section according to what area the character is walking on first.

Khris

Edit: @Dualnames:
Huh?

Code: ags
  if (GetGlobalInt(28) == 0) { // if the Globalint is 0 (the default)
    // open door:
    SetObjectView(3,2); // open door view
    SetGlobalInt(28, 1); // set GlobalInt to 1 so the door will be closed on next interaction
    RestoreWalkableArea(1);  // restore both areas
    RestoreWalkableArea(2);
  }
  else { // if GlobalInt is not 0, i.e. 1
    // close door:
    SetObjectView(3, 3); // closed door view
    SetGlobalInt(28, 0); // reset GlobalInt to 0 so door will be openend next time
    if (GetWalkableAreaAt(player.x, player.y)==1) RemoveWalkableArea(2);  // remove other area
    else RemoveWalkableArea(1);
  }


The return is unnecessary due to the else (which "remembers" whether the if was true and gets skipped even if the condition's outcome has changed).

Dualnames

Thing is it doesn't, I think. I think the door opens and closes instantly. Ah, I must be tired. Hope I didn;t confuse anyone.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Morgan

matti: that worked perfectly! thank you very much.

SMF spam blocked by CleanTalk