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.
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.
Dualnames, I think he's looking for something else. I hope I haven't messed up things so this will work:
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.
Edit: @Dualnames:
Huh?
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).
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.
matti: that worked perfectly! thank you very much.